Created
July 7, 2022 05:20
-
-
Save JustinGrote/a4565821456043205eebd10310e17b59 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