I've got a CSV file with a list of names in a "name" column. In a second CSV I have a list of names in a "name" column, and also their employee IDs in an "employeeid" column.
My desired output is this: take the "name" column in CSV1, compare it to the "name" column in CSV2, and wherever there's a match, take the name from the "name" column of CSV1 and the matching employee ID in CSV2, and create a new CSV3 with a "name" column and corresponding "employeeid" column.
Here is an image describing my question
I've started playing with import-csv to pull each CSV in as a variable, and also tinkered with piping that with select headers, but I don't understand the logic necessary to take username column matches between CSV1 and CSV2 and then combine that with employeeID from CSV2.
Thanks in advance for any guidance you can provide.
Brian
-- Updated 3/19
$csv1 = import-csv -Path "C:\csv1.csv" | select-object -ExpandProperty 'accountname' | Sort-Object | where {$_ -ne ""}
$csv2 = import-csv -Path "C:\csv2.csv" | select 'accountname','employeeid'
$accountNamesFromCSV2 = $csv2 | select-object -ExpandProperty accountname
$compareTheTWo = Compare-Object -ReferenceObject $csv1 -DifferenceObject $accountNamesFromCSV2 -ExcludeDifferent -IncludeEqual -passThru
-contains
operator should be useful here, and I suspect that the only cmdlets needed will beWhere-Object
andSelect-Object
(and the CSV cmdlets). – Jeff Zeitlin