I have a module xy which has several functions for the end user and several internal helper functions called by functions but not by the end user.
Get-Command -Module xy -CommandType function
lists all functions I have in my module folder (e.g. get-foo
and get-foo_helper
)
Is there a way to hide get-foo_helper
function from the end user who is using:
Get-Command -Module tcaps -CommandType function
One thing I have done is use the verb-noun naming convention for functions I want to export, but leave out the hyphen in helper functions.
Then,
export-modulemember *-*
takes care of only exporting what you want to export.You can use Export-ModuleMember or create a Module Manifest and specify the exported commands. You can use New-ModuleManifest to create a manifest file.
Just add Export-ModuleMember to the bottom of you module.
Let's say you have the following Functions in your module:
Add these lines to the bottom of the module file:
When you run Import-Module on this module, it will only import the functions defined by Export-ModuleMember.
Now let's say you also wanted to export an alias for New-Function1. just add this to the end of your module:
Now when you use Import-Module, it will load the functions you defined, as well as an alias (nf1) for New-Function1.
In many cases, a declared function can be replaced with a scriptblock (ie an anonymous function).