Last active
August 30, 2024 14:59
-
-
Save deadlydog/d04b5d43170a90d8bc0143373d90010f to your computer and use it in GitHub Desktop.
PowerShell template for a single-file script
This file contains 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
<# | |
.SYNOPSIS | |
PUT SHORT SCRIPT DESCRIPTION HERE AND ADD ANY ADDITIONAL KEYWORD SECTIONS AS NEEDED (.PARAMETER, .EXAMPLE, ETC.). | |
#> | |
[CmdletBinding()] | |
param ( | |
# PUT PARAMETER DEFINITIONS HERE AND DELETE THIS COMMENT. | |
) | |
process { | |
# PUT SCRIPT CODE HERE AND DELETE THIS COMMENT. | |
} | |
begin { | |
# DEFINE FUNCTIONS HERE AND DELETE THIS COMMENT. | |
$InformationPreference = 'Continue' | |
# $VerbosePreference = 'Continue' # Uncomment this line if you want to see verbose messages. | |
# Log all script output to a file for easy reference later if needed. | |
[string] $lastRunLogFilePath = "$PSCommandPath.LastRun.log" | |
Start-Transcript -Path $lastRunLogFilePath | |
# Display the time that this script started running. | |
[DateTime] $startTime = Get-Date | |
Write-Information "Starting script at '$($startTime.ToString('u'))'." | |
} | |
end { | |
# Display the time that this script finished running, and how long it took to run. | |
[DateTime] $finishTime = Get-Date | |
[TimeSpan] $elapsedTime = $finishTime - $startTime | |
Write-Information "Finished script at '$($finishTime.ToString('u'))'. Took '$elapsedTime' to run." | |
Stop-Transcript | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment