Avatar of cawasaki
cawasaki
 asked on

compare 2 csv file

i need to compare 2 csv file contain list of server:
the first file contain:

server1
server2
server3

the second file:

server0
server30
server1
server3
server2
server40

i need to compare this 2 csv file and only export the difference, the result will be:

server0
server30
server40

thanks for help
PowershellScripting Languages

Avatar of undefined
Last Comment
cawasaki

8/22/2022 - Mon
oBdA

This gets only names that are in the second file, but not in the first.
If you want names as well that appear only in the first file, but not in the second, just remove the line "Where-Object ..."
$outFile = 'C:\Temp\diff.csv'
$reference = Get-Content -Path 'C:\Temp\Servers1.csv'
$difference = Get-Content -Path 'C:\Temp\Servers2.csv'
Compare-Object -ReferenceObject $reference -DifferenceObject $difference |
	Where-Object {$_.SideIndicator -eq '=>'} |
	Select-Object -ExpandProperty InputObject |
	Set-Content -Path $outFile

Open in new window

cawasaki

ASKER
hello oBdA

Test it but the result is not correct, i have get the 2 line not present in first csv plus other line present in the 2 csv file
cawasaki

ASKER
test it gain, i dont now why every time it add this servername
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
cawasaki

ASKER
hi,

the last one work :)
thanks