Shared Private Functions In a Module

I have created a powershell module. lets call it Helper. Helper contains:

Private.psm1 contains functions that are used by X and Y but should not be publicly visible. X and Y consume the private.psm1 functions internally and export their own functions that wrap the low level private functions. The Helper.psd1 file further reiterates the functions that are exported in X and Y. However this does not seem to be working. Am I going about this right or do I need to duplicate the private functions across X and Y. (unhappy smiley)

We’d need to see your psd1 and psm1 files to know what’s going on for sure. I’ve fiddled with some dummy files, trying several sets of options on the psm1 and psd1 files, and so far haven’t been able to create a situation where unwanted functions wound up being exported.

On a side note, I rarely bother with nested modules. If there is code that’s shared across multiple files inside a script module, I tend to just create PS1 files and dot-source it. A single script module boundary tends to be enough, most of the time.

Sorry. That not it at all.

I can’t see the private function from module X or Y. I’m not even not sure if I should be able to. I’ll try to clarify the project structure.


  • Private.psm1
    – Get-Stuff()
  • X.psm1
    – Do-Stuff()
  • Y.psm1
    – Do-OtherStuff()

Do-Stuff() internally calls Get-Stuff(), so i need to be able to see this function from within a different module file. The same is true for Do-OtherStuff(). However I do not want to expose Get-Stuff() outside of the Helper module. This should only expose Do-Stuff and Do-OtherStuff().

Hope that is clearer.

Thanks. Dot sourcing a ps1 file is a obvious solution when you think about it… It worked perfectly.