locked
Compare Objects and keep additional columns RRS feed

  • Question

  • 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

    Computer Email
    Computer1 userA@company.com
    Computer2 userB@company.com
    Computer3 userC@company.com
    Computer4 userA@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 *

    Friday, November 15, 2019 6:00 PM

All replies

  • Compare-Object $MasterCSV  $CompareCSV -Property Email -IncludeEqual -ExcludeDifferent -PassThru

    help compare-object -online


    \_(ツ)_/

    Friday, November 15, 2019 6:14 PM