Powershell Can';无法从比较对象中获得所需的结果
示例代码:Powershell Can';无法从比较对象中获得所需的结果,powershell,powershell-4.0,powercli,Powershell,Powershell 4.0,Powercli,示例代码: $hosts = Get-View -ViewType hostsystem -Property name,network $clusters = Get-View -ViewType clustercomputeresource -Property name,network,host $hosts | Add-Member -MemberType AliasProperty -Name TEST -value MoRef $clusters | Add-Member -Me
$hosts = Get-View -ViewType hostsystem -Property name,network
$clusters = Get-View -ViewType clustercomputeresource -Property name,network,host
$hosts | Add-Member -MemberType AliasProperty -Name TEST -value MoRef
$clusters | Add-Member -MemberType AliasProperty -Name TEST -Value Host
我希望在解析数据时加快脚本速度,并希望使用Compare Object
然而,代码
Compare-Object $hosts $clusters[0] -Property TEST -IncludeEqual -ExcludeDifferent -PassThru
没有产出
代码
Compare-Object $hosts.test $clusters[0].test -IncludeEqual -ExcludeDifferent -Pass -PassThru
给了我精确的匹配,但没有穿过物体
很遗憾,我无法确定原因。在
$hosts | Add Member-MemberType AliasProperty-Name TEST-value MoRef
行中,您试图设置别名属性MoRef,但对于第一行中的主机$hosts=Get View-ViewType hostsystem-property Name,network
您没有选择此属性,因此无法设置此别名
请检查要比较的对象是否都包含正确的信息
行:Compare Object$hosts.test$clusters[0]。test-IncludeEqual-ExcludeDifferent-Pass-PassThru
将给出错误,因为-Pass
和-PassThru
都在这行代码中。
这条线不会穿过对象,因为您只比较一个属性,而不是整个对象
Compare Object$hosts$clusters[0]-属性测试-IncludeEqual-ExcludeDifferent-PassThru
看起来不错,我认为在参数完成后应该可以工作 您的上一个代码段中有一个虚假的-Pass
。除此之外,Compare Object
语句对我来说都很好。您能否提供样本数据(CSV格式)?