Dec 142008
 

No matter what the size of your organization in some way use documentation to do your Job. This is especially true for those of us who rely on Powershell to keep the ship running when we are not around to steer it. The problem is you don’t want to have to wade through comments to determine how to use a script written by a colleague when the boss needs the report yesterday and the author of the script is a not around. So add this quick snippet to the collection next time you want to polish off a script.

_____________________________________________________________________________________________________

#Add this snippet to the beginning of scripts execution block.

#Use this alternative version of the the if statement if your script requires parameters to execute properly:
#if((“-?”,”-help”,”?”,$NULL) -contains $args[0])

#Check the first text entered after the execution statement for the script.
if((“-?”,”-help”,”?”) -contains $args[0])
{

#What ever you want to say about how the script should be used, but here is an example.
Write-Host “Description: What does this script do?”
Write-Host “Usage: Script.ps1 -Parameter1 blah -Parameter2 blahagain”
Write-Host “Example: Script.ps1 `”dog`” `”cat`” ”
#Exits the script after outputting the usage.
exit 0
}

___________________________________________________________________________________________________

See I told you it was easy! And yes this snippet had a little inspiration from the Powershell section of  Microsoft’s DPM Team’s Blog. Yeah, I can’t believe that have one either…..

Leave a Reply