Skip to content

Instantly share code, notes, and snippets.

@mwallner
Created January 14, 2020 21:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwallner/f503666bd9ea480a3bef80318fe5be3e to your computer and use it in GitHub Desktop.
Save mwallner/f503666bd9ea480a3bef80318fe5be3e to your computer and use it in GitHub Desktop.
powershell cmdet vs basic function argument handling
function Get-EvilCmdLet {
[CmdletBinding()]
param(
[ValidateSet('A', 'B')]
$Category
)
Write-Output "= Get-EvilCmdLet ="
Write-Output "* PSBoundParameters"
$PSBoundParameters.Keys | % {
Write-Output " ** $_ -> $($PSBoundParameters[$_])"
}
Write-Output "* args"
$args | % {
Write-Output " ** $_"
}
}
function Get-EvilBasic {
param(
$Category
)
Write-Output "= Get-EvilBasic ="
Write-Output "* PSBoundParameters"
$PSBoundParameters.Keys | % {
Write-Output " ** $_ -> $($PSBoundParameters[$_])"
}
Write-Output "* args"
$args | % {
Write-Output " ** $_"
}
}
Get-EvilBasic "A" -foo bar -verbose
Get-EvilCmdLet "B" -foo bar -verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment