I have couple of csv excel sheet, that looks like this
Editors note: if you have a csv, then post a text representation of that csv!
> Get-Content .\Sheet1.csv Name,Age Xavier,20 Liam,19 Lisy,21 > Get-Content .\Sheet2.csv Name,Age Liam,19 Lisy,21 Frank,25
Could someone help me to make it work and get a csv out.
I am trying to compare column 'Name' values from csv 1 to csv2:
- if there is a match I want to store the value in an array called
array 1, finally export it to csv. eg -Liam and Lisy - if they do not match I want to store the values on
array 2, finally export it to csv. eg - Xavier
My code:
$source = Import-Csv C:\output\Source.csv
$target = Import-Csv C:\output\Target.csv
Creating array to store vales
$match = New-Object System.Collections.ArrayList
$donotmatch = New-Object System.Collections.ArrayList
Comparing column values
foreach ($i in $source) {
foreach ($s in $i.name) {
foreach ($t in $target) {
if ($n -eq $t.name) {
$match.Add($n)
}
else
{
$donotmatch.Add($n)
}
}
}
}
$match.ToArray()
$donotmatch.ToArray()
Compare-Object. And of course even before that you should search for your question here in SO. Something like this is asked about at least 10 times a week. ;-)