I have a large script which I’m now cleaning up with the use of functions.
But, I’ve found that it gets kinda messy to put them all at the top of the script.. I have to scroll past hundreds of lines of codes to get to the script itself..
How do you guys keep your scripts tidy? Do you have your functions in a separate file?
Try #Region and #EndRegion
If you use PowerGUI script editor you can use regions like this:
When you open the script in PowerGUI script editor the regions will be collapsed so you don’t have to scroll to get to the main logic. This also works in Microsoft ISE. Not all script editors honor the region tags though.
Try dot-sourcing or importing as module
Another way is to externalize your functions either into another script and do what is called dot sourcing
. C:\myfunctions.ps1or put them in a module file named with a.psm1extension and useImport-Module.