Create PowerShell Modules on the Fly - Publish-Module.ps1

Put a collection of your favorite functions into their own PS1 files, complete with any code you used for testing purposes and this script will extract ONLY the function portion and gather all the functions into a PowerShell module. The module will be named after the folder name they're placed under. Script will also support nested folders, meaning all functions in all subfolders will be contained int he main module, but a second module named after the nested folder will be created and will only contain the functions from it's folder and every nested folder under there, etc.

Functions
-->Module1
---->Module2
-->Module3

Point the script at Functions and 3 modules will be created. Module1 will contain all functions in the Modules1 and Modules 2 folder. Module 2 will only contain the functions in the Modules2 folder. Module3 will be a separate module and only contain the functions in that folder.

Manifest file for the module will also be created with the correct PowerShell version requirement (assuming you specified this with the "#requires -Version" code in your functions), and the script will also increment the version number of the module based on the number of PS1 files that have changed from the last publish.

Manifest file can also be edited to suit your requirements.

#Publish and #EndPublish allows you to add statements to your module. Any code located between these lines will be included in the module. This allows the inclusion of alias' or whatever other code you need to run when the module is loaded.

Write-Host "Not in the module"
#Publish
Write-Host "This is in the module"
Write-Host "This is too"
#EndPublish
Write-Hote "But this isn't"