Add custom object to array if object not exists


Log file with many lines of comma separated data (no headers)

Log file does contain lines that are identical to other lines

Created custom object by splitting log file lines and assigning headers

How do I skip adding this object to an array if a matching object already exists ?


File contains lines 






$records = new-object system.collections.arraylist

foreach ($line in $file)


$split = $line.split(",")

$record = [pscustomobject]@{

Info1 = $split[0]

Info2 = $split[2]

Info3 = $split[3]

Info4 = $split[4]

$records += $record


As you can see, when I get to the 4th line of the log file it is the same as the first line - so I don't want to add it to the array ($records).

The real log files I'm dealing with contain 20000+ lines so looping through for comparison will be heavy on time and resources.  Was looking to use something inbuilt like -notcontains but cannot seem to get it to work on objects.