I have two System.Data.DataSet objects that I wish to compare using the Compare-Object Cmdlet. I wish to output a dataset with the columns of the original datasets but with only the differences and an additional column with the SideIndicator values calculated in the Compare-Object cmdlet.
Assuming I have these two CSV’s:
#C:\test.csv
"firstName","lastName"
"Bruce","Wayne"
"Clark","Kent"
#C:\test2.csv
"firstName","lastName"
"Peter","Parker"
"Clark","Kent"
"Jean","Grey"
I would like to use the results of:
compare-object (Get-Content C:\test.csv) (Get-Content C:\test2.csv)
to populate a dataset formatted as follows:
#desiredResult
"firstName","lastName","SideIndicator"
"Peter","Parker","=>"
"Jean","Grey","=>"
"Bruce","Wayne","<="
Thanks,
Zach
This should give
$outputthe value you are looking for.When you use
Get-Contentof a file, it puts each line as an object of the array. This treats thefirstnameandlastnameas a single line, which exists in both arrays. Therefore, it’s not returned with thecompare-objectsince it is in both.When you use
Import-Csvit takes the first row as headers, and makes them properties to the array. Each line after that is added to the property based on it’s location in the.csv. This means thatcompare-objectcan compare them with different arrays, and maintain the properties to an output.