Last active
September 1, 2023 19:43
-
-
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
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 | |
Process pipeline junk | |
.NOTES | |
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( | |
[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