Best Practice For Splitting Files

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

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.

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

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