0

Sample code:

$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

I would like to speed my scripts when parsing data and want to use Compare-Object.

However, the code

Compare-Object $hosts $clusters[0] -Property TEST -IncludeEqual -ExcludeDifferent -PassThru

is giving no output.

The code

Compare-Object $hosts.test $clusters[0].test -IncludeEqual -ExcludeDifferent -Pass -PassThru

is giving me exact matches, but not passing through the objects.

Unfortunately I cannot determine why.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Ondrej
  • 1
  • Your last code snippet has a spurious `-Pass` in it. Other than that both `Compare-Object` statements worked fine for me. Can you provide sample data (in CSV form)? – Ansgar Wiechers Jun 28 '17 at 08:13

1 Answers1

0

In the line $hosts | Add-Member -MemberType AliasProperty -Name TEST -value MoRef you are trying to set an alias property MoRef, but for hosts in the first line $hosts = Get-View -ViewType hostsystem -Property name,network you are not selecting this property, so this alias cannot be set.

Please check if the objects to compare are both containing the correct information.

The line: Compare-Object $hosts.test $clusters[0].test -IncludeEqual -ExcludeDifferent -Pass -PassThru will give an error because both -Pass and -PassThru are in this line of code. This line will not passing through the object, because you are only comparing one property and not the whole object.

Compare-Object $hosts $clusters[0] -Property TEST -IncludeEqual -ExcludeDifferent -PassThru looks fine and I think this should work when the parameters are complete.

MarliesV
  • 65
  • 3