Passing Hashes to a Powershell function problem

后端 未结 2 784
时光取名叫无心
时光取名叫无心 2021-01-28 17:18

I must be missing something. i have to variables: $var1 and $var2

$var1 | gm 
 TypeName: System.Collections.Hashtable

Each of them has IP and Por

相关标签:
2条回答
  • 2021-01-28 18:10

    I've had problems with my functions when calling them with parenthesis. Have you tried calling your function like so?

        CompareData -data1 $var1 -data2 $var2
    
    0 讨论(0)
  • 2021-01-28 18:16

    When you use parentheses, PowerShell constructs an array with all the values in it, and uses that as the value for one parameter.

    So, CompareData ($var1, $var2) is equivalent to CompareData -data1 @($var1, $var2) with no value specified for the -data2 parameter.

    If you use CompareData -data1 $var1 -data2 $var2 as suggested by @dwillits you should get the result you expect.

    0 讨论(0)
提交回复
热议问题