Created
April 28, 2020 06:33
-
-
Save mark05e/d26c0f03956d4783373a4aff8440927b to your computer and use it in GitHub Desktop.
My powershell boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.NOTES | |
=========================================================================== | |
Author: Mark | |
Created on: 2020-04-28 | |
Organization: XXXXXX | |
Filename: MyPowershellBoilerplate.ps1 | |
=========================================================================== | |
.DESCRIPTION | |
My powershell boilerplate | |
#CHANGE HISTORY | |
2020-04-28 : Initial Version | |
#> | |
#Requires -Version 5 | |
Set-StrictMode -Version Latest | |
$ErrorActionPreference = "Stop" | |
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew() | |
#region Variables | |
$scriptDir = Split-Path -LiteralPath $PSCommandPath | |
$startingLoc = Get-Location | |
Set-Location $scriptDir | |
$startingDir = [System.Environment]::CurrentDirectory | |
[System.Environment]::CurrentDirectory = $scriptDir | |
$trace_path = ".\TraceLogs\" | |
#endregion | |
#region Transcripts | |
# Get Execution time | |
$startDate = Get-Date -format 'yyyy-MM-dd' | |
$startTime = Get-Date -format 'HH:mm' | |
# Start Transcript | |
$fileToWrite = (Resolve-Path -Path $trace_path).Path + $startDate + '.log' | |
Start-Transcript -Path $fileToWrite -Append | Out-Null | |
Write-Output -InputObject "`n########## Starting script $($PSCommandPath) on [$($env:computername)] at $($startDate) $($startTime) ##########" | |
#endregion | |
try | |
{ | |
# TODO: Insert script here. | |
} | |
finally | |
{ | |
Set-Location $startingLoc | |
[System.Environment]::CurrentDirectory = $startingDir | |
Write-Output "Done. Elapsed time: $($stopwatch.Elapsed)" | |
Stop-Transcript | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment