Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Last active May 8, 2025 18:20
Show Gist options
  • Save JohnL4/988ecd46e079c0aa2dd697d650486e8e to your computer and use it in GitHub Desktop.
Save JohnL4/988ecd46e079c0aa2dd697d650486e8e to your computer and use it in GitHub Desktop.
awk-like BEGIN and END processing of a pipeline in PowerShell; adding -Verbose and -WhatIf support via CmdletBinding; Template for a whole script.
<#
.SYNOPSIS
Process pipeline junk
.DESCRIPTION
Longer description of script/cmdlet/function goes here.
.EXAMPLE
Sample usages, if helpful. Can be repeated for multiple examples.
.NOTES
[Stuff of interest not necessarily required as part of Description section. Could maybe put futures/todos here.
The mere presense of CmdletBinding() gives the -Verbose (-vb) parameter, so all Write-Verbose statement actually work.
Adding SupportsShouldProcess=$true gives -WhatIf, and all things this function/script does that can affect the system get turned
into verbose dry run ops.
#>
[CmdletBinding(SupportsShouldProcess=$True)] # Attribute goes on 'param' keyword.
param(
# Documentation for this parameter goes here, in the form of a comment. Be sure to document special values (if any).
[Parameter( ValueFromPipeline=$true)]
$InputObject
)
BEGIN {
Write-Verbose "BEGIN"
}
PROCESS {
Write-Verbose "PROCESS"
}
END {
Write-Verbose "END"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment