Author Posts

December 4, 2014 at 1:04 am

Hello everyone,

The below script works well for comparing two CSV files and exports output ,

#Comparing the PrePatchReport & PostPatchReport
$file1 =Import-Csv D:\List1.csv
$file2=Import-Csv D:\List2.csv
# get list of CSV properties
$props1 = $file1 | gm -MemberType NoteProperty | select -expand Name | sort
$props2 = $file2 | gm -MemberType NoteProperty | select -expand Name | sort
# first check that properties match
if(Compare-Object $props1 $props2)
{
throw "Properties are not the same! [$props1] [$props2]"
}
# pass properties list to Compare-Object
else
{
$CR=Compare-Object -ReferenceObject ($file1) -DifferenceObject ($file2)
$CR|Export-Csv D:\Results.csv -Append -NoTypeInformation
}

List1.csv

KBNumber
2112212
5656666
2211000
8897991

List2.csv

KBNumber
2112212
5656666
2211000

and output is:

Results.csv

"InputObject","SideIndicator"
"@{KBNumber=8897991}","<=" "@{KBNumber=7665756}","<=" "@{KBNumber=9837129}","<=" "@{KBNumber=1212111}","<=" Kindly help me out in ways to improve the format of my output. Expected Format is: Results.csv KBNumber 8897991 7665756 9837129 1212111 Thanks in advance...

December 4, 2014 at 1:32 am

Try replacing your last line

$CR|Export-Csv D:\Results.csv -Append -NoTypeInformation

with

$CR | Select-Object -ExpandProperty KBNumber | Export-Csv D:\Results.csv -Append -NoTypeInformation