I have 2 csv file. 1st file have deviceName and 2nd file have deviceName and id as a header of the column. I need to check if the first file deviceName is present in file first column deviceName and i need the output as the corresponding id value from 2nd file.

1

There are 1 best solutions below

3
Civette On

Not sure what is the expected output but this works and filters out file 2 values based on file 1.

Adapt delimeter and encoding accordingly your need, mine being ";"

$file1 = Import-Csv -Path path_to_csv1 -Delimiter ";" -Encoding Default
$file2 = Import-Csv -Path path_to_csv2 -Delimiter ";" -Encoding Default

$file2 | Where-Object { $_.deviceName -in $file1.deviceName}