Skip to content

kayasax/PowershellTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowershellTemplate

An attempt to create a templating system for powershell.

The main goals of this set of scripts are:
  • 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
The workflow for creating a new script will be:
  1. Edit preferences.ps1 to define your default values (should be done once)
  2. Create a new template in template repository
    PS> Newtemplate.ps1 -name MyTemplate
    This will create MyTemplate.ps1t in the repository (defined in preferences.ps1)
  3. 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
  4. Generate the script
    PS>NewScriptFromTemplate.ps1 -template MyTemplate -name MyScript.ps1
    will create MyScript.ps1 in the current directory
Error handling

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
Email alert sample

You can also set $EventLogAlert tp $true to create an event log which will produce something similar in application event log eventlog alert

Logging feature

You can use the provided log function to record message on file and screen with basic colour highlights log to screen
log to file

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

About

An attempt to create a templating system for powershell.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published