The objective is to compare two files, one reference list the other is the testing list. My colleague helped me wrote a script to do the comparison, there were many false positives, so here’s his script:
$output = Compare-Object $file1 $file2 -Property ip -IncludeEqual | Where-Object {$_.SideIndicator -eq "<="} $output | select ip | Export-Csv .\logs\xxx_ip_diff.csv -NoTypeInformation
The output always give me items i have on both files and some items from file1.
From stackoverflow i have found a solution to this problem.
See here
So based on the solution, I modified the commands like this:
function find_discrepancy($devices) { foreach($device in $devices.Keys) { $diff = (Import-Csv "C:\Temp\${device}_ip.csv").IP Compare-Object $base $diff -IncludeEqual | Where-Object { $_.SideIndicator -eq '<=' } | ForEach-Object { $_.InputObject } | Set-Content "C:\temp\diff_${device}_ip.csv" } }
So actually to properly enumerate the objects that has "<="
I need to use the command foreach-object.