Typical practice is to organise your functions in to individual files under private and public folders. Public are ones your users will call, private are internal to the script. Then you can use a loop to load them all, as well as use the module manifest to expose the public ones:
$Public = @( Get-ChildItem -Path "$PSScriptRoot\Public\*.ps1" ) $Private = @( Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" )
@($Public + $Private) | ForEach-Object {
Try {
. $_.FullName
} Catch {
Write-Error -Message "Failed to import function $($_.FullName): $_"
} }
Export-ModuleMember -Function $Public.BaseName Export-ModuleMember
-Variable 'LogPath'
Example:
https://github.com/markwragg/Powershell-SlackBot/tree/master/SlackBot
The module manifest is still worthwhile, it delivers other benefits like allowing cmdlets to be discoverable even if the module isn't loaded and declaring dependencies (such as format xml files, or other modules that this module depends on). It's also a requirement of publishing the module in to the Powershell Gallery.