Skip to content

Instantly share code, notes, and snippets.

@maxfunke
Created July 3, 2018 10:05
Show Gist options
  • Save maxfunke/d801858b2a1b01714dcb0193c188ee28 to your computer and use it in GitHub Desktop.
Save maxfunke/d801858b2a1b01714dcb0193c188ee28 to your computer and use it in GitHub Desktop.
Boilerplate for powershell scripts
#Requires -Version 3
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>
.INPUTS
<Inputs if any, otherwise state None>
.OUTPUTS
<Outputs if any, otherwise state None - example: Log file stored in C:\Windows\Temp\<name>.log>
.NOTES
Version: 1.0
Author: <Name>
Creation Date: <Date>
Purpose/Change: Initial script development
.EXAMPLE
<Example goes here. Repeat this attribute for more than one example>
#>
#--------[Params]---------------
Param(
[parameter(Mandatory=$True,ValueFromPipeline=$true)] [Array]$MyParam
)
#if (-not($PSBoundParameters.ContainsKey("MyParam"))) {
# Write-Output "Value from pipeline"
#}
#--------[Script]---------------
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$scriptDir = Split-Path -LiteralPath $PSCommandPath
$startingLoc = Get-Location
Set-Location $scriptDir
$startingDir = [System.Environment]::CurrentDirectory
[System.Environment]::CurrentDirectory = $scriptDir
try
{
# >>>>>> Insert script here.
}
finally
{
Set-Location $startingLoc
[System.Environment]::CurrentDirectory = $startingDir
Write-Output "Done. Elapsed time: $($stopwatch.Elapsed)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment