I am comparing 2 csv files against IP address.
Below is the code, but it is not giving me the correct report. there are IP addresses present in $CSV2 but it is not showing
$CSV1 = Import-Csv -Path "E:\IP_Details.csv"
$CSV2 = Import-Csv -Path "E:\IP_Details_1.csv"
$Count = $CSV1.Count
$Results = For ($i = 0; $i -lt $Count; $i++) {
$IP_one = $CSV1[$i].'IP adress'.Trim()
$IP_two = $CSV2[$i].'IP adress'.Trim()
If ($CSV1[$i].'IP adress' -eq $CSV2[$i].'IP adress') {
$Match = "Match"
}
Else {
$Match = "Not Match"
}
[PSCustomObject]@{
Value = $CSV1[$i].'IP adress'
IPName = $CSV1[$i].IPName
Results = $Match
}
}
$Results | Export-Csv -Path "E:\File.csv" -NoTypeInformation
Please let me know what is wrong in the code
Got the below lines which is working fine
$file1 = import-csv -Path "E:\InfoBlox_Used_IP_Details.csv"
$file2 = import-csv -Path "E:\CMDB_IP_Details.csv"
Compare-Object $file1 $file2 -property 'IP adress' -IncludeEqual | Export-Csv -Path e:\testmantest2.csv
but it is giving me output like
"IP adress","SideIndicator"
"10.15.9.8","=="
"10.15.9.6","=="
"10.15.9.14","=="
"10.12.21.10","<="
but I need output like below where == should be match and >= is not match
"IP adress","IP Name","Status"
"10.15.9.8","one","match"
"10.15.9.6","two","match"
"10.15.9.14","three","match"
"10.12.21.10","four","Not macth"
Can you please let me know how can I do that
$Count = $CSV1.Count, are you sure CSV2 has the same number of rows ?