question

KalaimaniThirupathi-5306 avatar image
0 Votes"
KalaimaniThirupathi-5306 asked IanXue-MSFT answered

PowerShell two CSV comparison

I have two CSV files one yesterday's and the other one is today's, I need to compare the VM name object and get only the newly report VM name in the report. Can you help me with this? I was trying a lot but not working.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

Hi,

Suppose there's a column with the header "name" in your csv files, you can get the newly added VMs like below.

 $yesterday = "C:\temp\yesterday.csv"
 $today = "C:\temp\today.csv"
 $vmyesterday = Import-Csv -Path $yesterday
 $vmtoday = Import-Csv -Path $today
 $vmtoday | Where-Object{$_.name -notin $vmyesterday.name} | Select-Object name


Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.