I use this code for matching two CSV file and get the columns i need
in this code i compare the data Matricule name and Firstname and when I get a match I can retrieve the column 'IGG'
But it is very slow... (20min for 18 lines)
Someone can help me with this ?
Here is my code :
foreach ($item in $fileContentIMM)
{
try
{
$Matricule = $item.'Matricule'
$name = $item.'Nom'
$firstname = $item.'Prenom'
# find first matching row in $$fileContentMagic using wildcard
$objMatch = $fileContentMagic | where { $_.'Matricule' -eq $Matricule -and $_.'NOM' -eq $name -and $_.'PRENOM' -eq $firstname}
##### check if any match found
if ($objMatch -eq $null)
{
$item | ForEach-Object {
$filechecktrue += [pscustomobject]@{
'MATRICULE' = $item.'Matricule'
'IGG' = 'noSet'
'NAME' = $item.'Nom'
'FIRSTNAME' = $item.'Prenom'
'SERVICE' = $item.'Service'
'Immeuble'= $item.'Immeuble'
'Niveau' = $item.'Niveau'
'Loc.' = $item.'Loc.'
'PDT' = $item.'PDT'
'Occ.' = $item.'Occ.'
'Site' = $item.'Site'
}
}
}
else
{
$item | ForEach-Object {
$filechecktrue += [pscustomobject]@{
'MATRICULE' = $item.'Matricule'
'IGG' = ($objMatch.'IGG' -join '/')
'NAME' = $item.'Nom'
'FIRSTNAME' = $item.'Prenom'
'SERVICE' = $item.'Service'
'Immeuble'= $item.'Immeuble'
'Niveau' = $item.'Niveau'
'Loc.' = $item.'Loc.'
'PDT' = $item.'PDT'
'Occ.' = $item.'Occ.'
'Site' = $item.'Site'
}
}
}
}
catch
{
"ERROR: Problem reading line - skipping :" | Out-File $LogFile -Append -Force
$item.nom + $item.prenom + $item.service| Out-File $LogFile -Append -Force
}
}
Compare-Object?Write-Host "import done"to determine that it's not reading of the file that is slow?