
Powershelling properly
The best ways to be able to look at your scripts some weeks/months/years after writing it is to script properly.
Here below is the format at always use, I use it as a script template :
<# .SYNOPSIS Write a little Synopsis about the script purpose .DESCRIPTION AUTHOR : Chris ROUALIN - powershelltips.fr Write a little description about the script purpose .PARAMETER Subject Using -Subject parameter for the script. .PARAMETER Message Using -Body parameter for the script. .EXAMPLE PS C:\>.\Script-Template.ps1 -Subject "Powershell" -Message "Show how to use Powershell script template" .NOTES This is just an example of a notes displayed in help .LINK https://powershelltips.fr #>
This part make your script reachable with the Get-Help command :
Then, use some comments to create “section” in your script, such as :
##### VARIABLES ##### FUNCTION ##### PREREQUISITES ##### MAIN
So your powershell script will be easy to read/modify, adapt if the script is moved or if any variable has to be modified…
Also, never forget to comment as much as you can your script ! Every “block” need a comment to make it readable quickly !
Remember also that aliases are not welcome in a script, because not everyone knows what “%” means for example !
Cheers !