The only thing I can think of is that you have multiple CSV files for the same system name, so it’s appending different comparisons to the same output file.
I just checked again. That’s not the case Matt. What does the -Append do? I don’ t know a lot, but seems to me row appending is going on.
Thank you.
Victor.
Append ensures the file is not overwritten each time a row is exported. Otherwise you would end up with only one row (the last one) in your output file.
What’s the output from this?
$fileList = Get-ChildItem -Path 'C:\Temp\KAIZEN\Server_services'
$Names = foreach ($file in $fileList) {
Import-Csv -Path $file.FullName | Select-Object -ExpandProperty SystemName
}
$fileList.count
($Names | Select-Object -Unique).Count
Hi Matt,
See below please:
I don’t get why we have 2183 twice!
I am going to clean some clean up.
Thank you,
Victor.
No that’s OK, the numbers should match. I was checking that the number of unique system names was the same as the number of files.
The only other thing I can think of if you’re getting duplicates in the output is did you run the script more than once? A subsequent run will append to the existing file.
Hi Matt,
I didn’t run the script more than once. But to eliminate an error on my part, I have deleted everything and I am going to download again the services list from the network share and run the script again.
This might take a bit of time though.
Thank you.
Victor.
Matt,
I have to thank you for your patience!.
The numbers are OK now. I must have run it twice. I just don’t recall doing that or why I would do so.
As a gesture to your support, please check out the name of the folder that $row exports to!
$referenceData = Import-CSV -Path ‘C:\Temp\KAIZEN\Non-default services detection\beevehOIIMS13.csv’
$fileList = Get-ChildItem -Path 'C:\Temp\KAIZEN\Server_services'
foreach ($file in $fileList) {
$csv = Import-Csv -Path $file.FullName
foreach ($row in $csv) {
if ($row.Name -notin $referenceData.Name) {
$row | Export-CSV -Path "C:\Temp\KAIZEN\Matt\$($row.SystemName).csv" -Append
}
}
}
Thank you very much.
Victor.
You may add a “timstamp” to your filenames to circumvent such problems in the future.