Iam trying to merge two csv files with common column name but one has 22 row and other just 16.
1st CSV 2nd CSV
Name Service_StatusA Name Service_StatusB
IEClient running IEClient Manual
IE Nomad running IE Nomad running
Data Usage running Print Spooler Manual
Print Spooler running Server running
Server running
I want to merge this to a single csv
Name Service_StatusA Service_StatusB
IEClient running Manual
IE Nomad running running
Data Usage running
Print Spooler running Manual
Server running running
$file1 = Import-Csv -Path .\PC1.csv
$file2 = Import-Csv -Path .\PC2.csv
$report = @()
foreach ($line in $file1)
{
$match = $file2 | Where-Object {$_.Name -eq $line.Name}
if ($match)
{
$row = "" | Select-Object 'Name','Service_StatusA','Service_StatusA',
$row.Name = $line.Name
$row.'Service_StatusA' = $line.'Service_StatusA'
$row.'Service_StatusB' = $match.'Service_StatusB'
$report += $row
}
}
$report | export-csv .\mergetemp.csv -notype -force
how to compare the row values before merging