PowerShell script template

This file is the Powershell template file that I use when creating PowerShell scripts.

The code below is a functioning PowerShell script for you to build on, it has the syntax for the Get-Help cmdlet to function correctly and takes three parameters some mandatory some not, it also outputs to the screen the script execution start & end time along with elapsed time.

Download file : Powershell Template as a text file.

<#    .SYNOPSIS        This script will ....    .DESCRIPTION        A Script description & version history.        --------------------------------------------------------        History        Version number | Data            | Comment         1.00           | <date>          | Initial script.         --------------------------------------------------------    .LINK        /archives/322    .EXAMPLE        <scriptName> -Param1 value -Param2 value 		<scriptName> -Param1 value -Param2 value -Param3 (optional) value#>Param (    [Parameter(Mandatory=$true, HelpMessage="Please enter a string value")]    [alias("Param1")]    [ValidateNotNull()]    #String value.     [string]$stringValue,     [Parameter(Mandatory=$true, HelpMessage="Please enter a numeric value.")]    [alias("Param2")]    [ValidateNotNull()]    #Number value.     [int]$intValue,    [Parameter(Mandatory=$false, HelpMessage="Please enter a string value (Optional).")]    [alias("Param3")]    [ValidateNotNull()]    #Optional string value.    [string]$optionalStringValue)$startTime = Get-DateWrite-Host "Start time : $startTime" #Passed valuesWrite-Host "Param1 : " $stringValueWrite-Host "Param2 : " $intValueWrite-Host "Param3 (optional) : " $optionalStringValue$endTime = Get-DateWrite-Host "Script execution time : $( New-TimeSpan $startTime $endTime)." Write-Host "End time : $endTime"