Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Compare Objects and keep additional columns

$
0
0

I'm trying to figure out the best way to accomplish this task. Any guidance is much appreciated!

I have 2 CSV files. The 1st file has 2 columns (Computer & Email). The 2nd file has 1 column (Email). I need to compare both files based on the Email column and return the matches. The output should included the Email and Computer columns.

MasterFile.csv

ComputerEmail
Computer1userA@company.com
Computer2userB@company.com
Computer3userC@company.com
Computer4userA@company.com

CompareFile.csv

Email
userA@company.com
userC@company.com

My code thus far:

$MasterCSV = Import-Csv -Path C:\MasterFile.csv
$CompareCSV = Import-Csv -Path C:\CompareFile.csv
Compare-Object -ReferenceObject $MasterCSV.Email -DifferenceObject $CompareCSV.Email -IncludeEqual -ExcludeDifferent | Select *


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>