This topic contains 4 replies, has 2 voices, and was last updated by
December 22, 2014 at 7:43 am #21351
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)
December 22, 2014 at 7:52 am #21353MemberPoints: 0Rank: Member
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.
December 22, 2014 at 7:54 am #21354MemberPoints: 0Rank: Member
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.
December 22, 2014 at 8:01 am #21355
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.
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.
December 22, 2014 at 8:24 am #21356
Thanks. Dot sourcing a ps1 file is a obvious solution when you think about it.. It worked perfectly.
The topic ‘Shared Private Functions In a Module’ is closed to new replies.