i'm trying to verify if an object exist in a list imported from 2 CSV files I get an error even though the 2 objects are similar
$CSV1 = Import-CSV $path $delimiter $header
$CSV2 = Import-CSV $path2 $delimiter $header
$myList = New-Object -TypeName 'System.Collections.ArrayList';
$myList.add("") | Out-Null
Foreach($value in $CSV1)
{
$obj = $value.PSObject.Copy()
$obj.Name = GetNameRef($value.Name)
$obj.IP = GetIPRef($value.IP)
if(!($CSV2.contains($obj)))
{
$myList.Add($value)|Out-Null
}
}
$myList | Format-Table * | Out-File ".\Result.txt"
So when i check manually i found a object in CSV2 with the same value for all properties but when i do CSV2.Contains, He didn't return "True"
I know it's like a reference problem but i didn't found any information about that actually or only to compare 1 propertie
The both CSV file has the same template like
First CSV file :
Name,ServerName,IP,Mono
Luc,PM45,255.245.22.21,MonoY
Ced,PC78,245.222.1.12,MonoX
Second CSV file
Name,ServerName,IP,Mono
John,PM45,255.245.22.20,MonoY
Dab,PC75,245.222.11.12,MonoX
In my project for exemple The value Luc and John with IP 255.245.22.21 and 255.245.22.20 refer to the same value, I found reference with GetNameRef() and GetIpRef()
So I modify some value to see if exist in the second CSV file But all value don't have equivalent in second CSVfile and i want found them
Exemple :
i have $object1 with value of the first line of CSV file1
i have $object2 with value of the first line of CSV file2
so i have :
$object1 :
Name = Luc,
ServerName = PM45,
IP = 255.245.22.21,
Mono = MonoY
$object2:
Name = John,
ServerName = PM45,
IP = 255.245.22.20,
Mono = MonoY
Now $obj take value of $object1 and i modify Name and IP to obtain this
$object1 :
Name = Luc,
ServerName = PM45,
IP = 255.245.22.21,
Mono = MonoY
$object2:
Name = John,
ServerName = PM45,
IP = 255.245.22.20,
Mono = MonoY
$obj :
Name = John,
ServerName = PM45,
IP = 255.245.22.20,
Mono = MonoY
So $obj and $object2 have same value properties
pscustomobjects are not comparable. You need to write your own logic for thatequalvalues? Which fields would you use for that? Obviously not all, because the IP's don't match anywhere..