Does your company have a lot of PowerShell scripts? Do they all follow the same template? No? You are not alone.
In my experience, troubleshooting scripts is much easier if all the scripts have the same look.
This script not only uses logging for errors, but can also be run in verbose mode so that the errors display in the PS session.
How to use the PowerShell Template
Download the template:
Edit the script name, description, and author.
Hey, if you are super cool you could add help features. I’m not that cool.
You might even want to add a changelog!
This is the function that runs the entire script.
The build in functions are:
o This function logs all of the activity from the script into a log file
o This is where ALL script variables go. You don’t want to have to change variables throughout the script. Instead, you want a central location for them
o This is where you would import any PS modules needed for the script
· Add your own functions
This is the function that sets all of the variables used in the script.
The $Script.LoggingPath variable is where the log file will get written to.
This is the function that imports PowerShell Modules. I usually create a variable for the module in the SetGlobalEnvVariables function and then reference them here.
This is the function that will construct the log file containing any errors.