Author Posts

September 13, 2017 at 6:36 pm

I currently have a script that is reaching 500 lines and I'm barely half way through creating it.

What are the recommended practices for handling large scripts. Do you split them? If so, how do you handle the execution of them, do you just 'dot-source' them? For modules, do you do use a .psd with nested modules?

The same question goes for handling large pester scripts as those aren't complex but they have a lot of lists of things to check and code blocks so can get lengthy quickly

September 13, 2017 at 6:43 pm

This is something we cover in "Learn PowerShell Toolmaking in a Month of Lunches." Essentially, you want to break down your functionality into discrete functions, with a controller script that calls them all in the right order and combination. The functions go in a .psm1 script module. This does require you to really think about what a "task" consists of, and make each function a very discrete, small-as-possible "task." This makes development and debugging easier, as well as maintenance.

September 13, 2017 at 6:46 pm

Sorry I should have clarified. My script is actually a module in a single file. It has a large class created at the top followed by several advanced functions. Once you add in all the help comments etc, it is getting quite large

September 13, 2017 at 8:21 pm

This might be overkill for what you're looking to do, but I follow a similar format for module development.

https://xainey.github.io/2017/powershell-module-pipeline/