An attempt to create a templating system for powershell.
- Improve scripts consistency among your scripters team
- Provide a solid fundation for new script
- Ease the reuse of existing functions without copy/paste code extracts
- Edit preferences.ps1 to define your default values (should be done once)
- Create a new template in template repository
PS> Newtemplate.ps1 -name MyTemplate
This will create MyTemplate.ps1t in the repository (defined in preferences.ps1) - Edit error handling preferences and insert your code in the previously generated template
You can use the<include>
tag to reuse existing code from the function repository
eg:<include logging/log>
The content of the file log.ps1 found in the logging directory of the function repo will be inserted here at step 3 - Generate the script
PS>NewScriptFromTemplate.ps1 -template MyTemplate -name MyScript.ps1
will create MyScript.ps1 in the current directory
Basicaly your code will be executed in a giant try/catch statement and $ErrorActionPreference is set to STOP
This means every error encountered will be a terminated error and the instructions in the catch block will be executed.
By setting $EmailAlert to $true
an email will be sent when an error occured.
The mail will look like this
You can also set $EventLogAlert tp $true
to create an event log which will produce something similar in application event log
You can use the provided log function to record message on file and screen with basic colour highlights
The log function include a rotating system : you can specify a maxsize for logfile if logfile exceed this limit it will be rename and a new file will be created. You can specify how much old files you want to keep