Internal functions in PowerShell Module -


i'm writing module, , have helper functions don't want exposed, want available module functions internally. have set directory structure like:

root\ ..private ....invoke-privatetest.ps1 ....private.psd1 ....private.psm1 ..public ....get-something.ps1 ....public.psd1 ....public.psm1 ..test.psd1 

i've setup repository on github https://github.com/jpbruckler/test has module files in it.

the behavior i'm expecting get-something public function. when running get-command -module test should listed. on contrary, invoke-privatetest should not in output of command.

when calling get-something should output text invoke-privatetest called. instead, error stating command invoke-privatetest doesn't exist.

i explicitly saying in test.psd1 get-something function exported.

both private module , public module being called via nestedmodules property in test.psd1. or pointers appreciated.

@petseral pointed me in right direction. came down scoping issue. way had module arranged, each sub-module need make call load private module, bunch of code duplication - , hoping avoid splitting out helper functions.

to work, instead of multiple sub modules, broke public folder sub folders hold scripts similar things, removing .psd1 , .psm1 files public directory. did same thing private directory. left me bunch of loose .ps1 files load in test.psm1 following code:

$private = (get-childitem -path (join-path $psscriptroot 'private') -filter *.ps1) $public = (get-childitem -path (join-path $psscriptroot 'public') -filter *.ps1 -recurse)   foreach ($script in $public) {     . $script.fullname     export-modulemember $script.basename }  foreach ($script in $private) {     . $script.fullname } 

i've modified test module @ https://github.com/jpbruckler/test reflect changes made.


Comments