Splatting - Input string was not in a correct form

2019-08-04 02:11发布

问题:

I can't seem to get my splatting to work in my Invoke-WmiMethod command. I declare the hash table like so:

$HKU = 2147483651

$MyParams = @{
  'Class' = 'StdRegProv';
  'Name' = 'EnumKey';
  'ArgumentList' = "$HKU,''";
  'ComputerName' = '';
}

# additional code determining ComputerName... #

$MyParams['ComputerName'] = $MyComputer;
$Vals = Invoke-WmiMethod @MyParams

This line gives me the following error:

Invoke-WmiMethod : Input string was not in a correct format.
At C:\Users\Person\Desktop\tmp.ps1:160 char:20
+         $Vals = Invoke-WmiMethod @MyParams

Do you know what the problem could be?

回答1:

Try this:

$HKU = 2147483651

$MyParams = @{
  'Class' = 'StdRegProv';
  'Name' = 'EnumKey';
  'ArgumentList' = @($HKU,'');
  'ComputerName' = '';
}

$MyParams['ComputerName'] = $MyComputer;
$Vals = Invoke-WmiMethod @MyParams