Turning sideindicator into value

I’m comparing 2 csv by compare-object selecting 2 properties (fields in my csv) that interest me so like

$test = compare-object $a $b -property x,y -passthrugh

$test | foreach {

if($_.sideindicator -eq ‘<=’){

$.sideindicator = $.y

}


However, rather then getting the value for the found difference I get a whole hashtable containing the corresponding row in place of the sideindicator. When I run get-member against that new sideindicator value I see TypeName: Selected.System.Management.Automation.PSCustomObject. How do I get my value then?

I’m pretty unsure if I got what you expect. You might post some sample data and some sample result.

If you have these input objects:

$a = @’
x,y,z
a,b,zab
a,c,zac
'@ |
ConvertFrom-Csv

$b = @’
x,y,d
a,b,dab
c,a,dca
'@ |
ConvertFrom-Csv


And you run this:
Compare-Object -ReferenceObject $a -DifferenceObject $b -Property x, y -PassThru

the result will be this:
x y d   SideIndicator


c a dca =>
a c <=


If you run this
Compare-Object -ReferenceObject $a -DifferenceObject $b -Property x, y -PassThru -IncludeEqual

the result will be this:
x y z   SideIndicator


a b zab ==
c a =>
a c zac <=


If you change the input objects like this:
Compare-Object -ReferenceObject $b -DifferenceObject $a -Property x, y -PassThru

the result will be this:
x y z   SideIndicator


a c zac =>
c a <=


… and including -IncludeEqual like this:
Compare-Object -ReferenceObject $b -DifferenceObject $a -Property x, y -PassThru -IncludeEqual

the result will be this:
x y d   SideIndicator


a b dab ==
a c =>
c a dca <=

It’s much differently formatted in my case. Possibly as I create my variables using Import-CSV selecting multiple fields for review which then after Compare-Object all display in list format with side indicator as the last value. If I limit by running something like below after my foreach loop

$test | select a,b,@{l='MyValue';e={$_.sideindicator}}
I was expecting to get only the values I'm interested in so where the "a" fields match (names come in this column) I want to see what's in corresponding "b" fields only where they don't match rather than getting the side indicator as the 3rd column.