-
-
Save aldrichtr/c5846e2f4e47f2d83cd75e1026209bc7 to your computer and use it in GitHub Desktop.
Get a hashtable of the parameters in your param block, useful for splatting.
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
using namespace system.collections.generic | |
function Get-ParamBlock ([String[]]$Name) { | |
[hashset[string]]$params = $PSCmdlet.MyInvocation.MyCommand.Parameters.Keys | |
$params.ExceptWith([string[]]([PSCmdlet]::CommonParameters + [PSCmdlet]::OptionalCommonParameters)) | |
$result = @{} | |
if ($Name) {$params = $params -in $Name} | |
foreach ($name in $params) { | |
$result.$name = $PSCmdlet.GetVariableValue($name) | |
} | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment