File 2 has 2 columns, servername, count but different column names.
I have to compare file 1 to file 2 such that if servername in file 1 matches with that in file2, compare the column 2 values for a condition is true( condition is file1 count-3 should be equal to file2 count)
$csv1 = Import-Csv .\p1hostcount.csv|Select-Object @{n=“cluster.name”;e={$.“Cluster”}},@{n=“rule_value”;e={$.“hostcount”}} < changing names in 1st file to be same of file2>
Seems that performance is an issue, I think you can do with a single for loop, but it’s not an easy task.
I came up with the following example:
for ($i = 0; $i -le $csv1.length; $i++) {
if ($csv2.ServerName.Contains($csv1[$i].ServerName)) {
$index = [array]::IndexOf($csv2.ServerName, $csv1[$i].ServerName)
Write-Output "$($csv1[$i].ServerName) found in Csv2 on index $index"
Write-Output "Rule value for ServerName $($csv1[$i].ServerName) in CSV1: $($csv1[$i].'rule_value')"
Write-Output "Rule value for ServerName $($csv2[$index].ServerName) in CSV2: $($csv2[$index].'rule_value')"
}
}
I added the output, so you can verify that the Server names are matching on the correct indexes.