Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Created July 7, 2022 05:20
Show Gist options
  • Save JustinGrote/a4565821456043205eebd10310e17b59 to your computer and use it in GitHub Desktop.
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.
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