Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabriel-vanca/fd76e61e4f49a583a62d9f25b864bcf8 to your computer and use it in GitHub Desktop.
Save gabriel-vanca/fd76e61e4f49a583a62d9f25b864bcf8 to your computer and use it in GitHub Desktop.
PowerShell template for a single-file script
<#
.SYNOPSIS
A brief description of the function or script. This keyword can be used only once in each topic.
.DESCRIPTION
A detailed description of the function or script. This keyword can be used only once in each topic.
.COMPONENT
The name of the technology or feature that the function or script uses, or to which it is related.
.FUNCTIONALITY
The keywords that describe the intended use of the function.
.PARAMETER <Parameter-Name>
The description of a parameter. Add a .PARAMETER keyword for each parameter in the function or script syntax.
Type the parameter name on the same line as the .PARAMETER keyword. Type the parameter description on the lines following the .PARAMETER keyword. Windows PowerShell interprets all text between the .PARAMETER line and the next keyword or the end of the comment block as part of the parameter description. The description can include paragraph breaks.
.INPUTS
None. You cannot pipe objects into this function.
.OUTPUTS
[System.String] - Add-Extension returns a string with the extensionor file name.
.EXAMPLE
A sample command that uses the function or script, optionally followed by sample output and a description.
Repeat this keyword for each example.
PS> extension -name "File" -extension "doc"
File.doc
.LINK
The name of a related topic. The value appears on the line below the ".LINK" keyword and must be preceded by a comment symbol # or included in the comment block.
Repeat the .LINK keyword for each related topic.
The .Link keyword content can also include a Uniform Resource Identifier (URI) to an online version of the same help topic.
The URI must begin with "http" or "https".
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-7.4
.NOTES
===========================================================================
Created with:
Created on: 21/07/2024 22:00
Created by:
Organization:
Filename:
Version: 1.0
Purpose/Change: Initial script development
==========================================================================
#>
#---------------------------------------------------------[PARAMETERS]--------------------------------------------------------
[CmdletBinding()]
param (
# PUT PARAMETER DEFINITIONS HERE AND DELETE THIS COMMENT.
)
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
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'))'."
}
process {
# PUT SCRIPT CODE HERE AND DELETE THIS COMMENT.
}
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