Get ValueFromRemainingArguments as an hashtable


Using [parameter(ValueFromRemainingArguments=$true)] one can get all the remaining arguments passed to the function into a variable as a list.

How can I get the remaining arguments as a hashtable type, for example for inputs like Function -var1 value1 -var2 value2?


There are multiple ways to achieve this. The following solution supports parameters with:

  • Simple value (single item)
  • Array value
  • Null value (switch)



Edit: Modified default value assigned to Hashtable keys: $htvars[$lastvar] = $true. Using $true as the default accounts for switch parameters and can make the resulting Hastable more “splattable”.


Get ValueFromRemainingArguments as an hashtable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply