Finished going through a recent NA TechEd2012 video Turn PowerShell Commands into Reusable CLI and GUI Tools by Don Jones.
Some of the advice I sort of knew and and followed.
- I knew how to make a PowerShell script module.
- I knew about the .SYNOPSIS, .EXAMPLE stuff.
- I sort of knew about using the param/paremeters though I didn't really understand it, just used it in a limited framework copy/paste sort of way. After the video I have a much better handle on how to leverage it.
What I really got out of it though was some new and better ways to leverage built in switches more effectively which I had no real clue about.
- Documenting not though #comments but using
Write-Verboseso that the
-verboseswitch works and you can see what a script is doing without pulling it up in an editor.
write-debugto leverage the
-debugswitch for your functions
- Using try/catch in your scripts so if a first part fails, then it skips the next parts on that one server.
- A clear example on how to use
Write-Objectwith a PSObject which I just used without understanding it.
$errorLogPathto create an error log
Below is the script he built for the presentation with the various examples. Save the below code as
MyTools.psm1 and load it up. Then run it against multiple systems without switches and using the
-verbose switches. Better yet, go watch the video.