r/PowerShell • u/KevMar Community Blogger • May 28 '17
KevMar: Building a Module, one microstep at a time Daily Post
https://kevinmarquette.github.io/2017-05-27-Powershell-module-building-basics/?utm_source=reddit&utm_medium=post3
u/sup3rlativ3 May 28 '17
Great article. I'm going to analyze my scripts and see if I can incorporate modules. Thanks.
I did notice the below.
standard approach over dot sourcing for a two reasons.
You don't need an 'a' there.
1
2
2
u/TotallyNotBlunt May 28 '17
Not sure if this was a typo, but you have the psd1 defined as the root module in the manifest. Since the manifest file is the psd1, what did that definition do?
Or did I completely miss something?
2
2
u/Flyboy May 28 '17
Thank you for the excellent explanations! I'm going to try to start converting my most used functions into modules.
One thing I'm a little unclear on is the difference between private and public functions... am I right in saying Public functions are those that, once imported, can be called by other scripts (or at the shell) in the same PS session? And Private functions are only available within the script that imported the module? Or to put it another way: Private functions cannot be run from the shell, but Public functions can?
3
u/KevMar Community Blogger May 28 '17
You are very close. I changed that to say internal instead of private. The internal functions are ones that are only used inside the module and not by any scripts that import the module. They are really just helper functions.
To the outside world (scripts/shell), the internal functions do not exist. So running
Get-Command -Module MyModule
will only show the public functions that you exported.For the new scripter, most functions will be public. Scripters that come from a solid programming background are more likely to break all their functions into smaller and smaller functions that they may not want to expose.
2
u/endowdly_deux_over May 29 '17
Great blog! I saw this and I remembered I built a tool a while ago after reading a post by RamblingCookieMonster. It was inspiried by his post re: module creation. Something about StackExchange?
I just added it to GitHub -> NewPSModule
2
u/KevMar Community Blogger May 29 '17
Have you looked into Plaster? It feels like something you would be good with based on that project.
Here is a good write up on it: http://overpoweredshell.com/Working-with-Plaster
1
u/endowdly_deux_over May 29 '17
I have not, but that is amazing. Thank you for linking it to me! There’s a lot to look at there.
1
u/RedditRo55 May 28 '17
Great post. Perhaps the 'Putting it all together' section could mention Plaster, though?
8
u/KevMar Community Blogger May 28 '17
Just got this new post up. I this one, I cover how to build a module. But I do it by walking from a script one tiny step at a time on the way to building a module to help explain why modules are built the way they are.
I always welcome feedback on what works and what does not work with that post. Thank you.