Saturday, June 22, 2013

Find duplicates in an array (Powershell)

The function takes on parameter, the array. It will return a string representing the duplicates

Function GetArrayDupes
{
   param($array)
   $hash = @{}
   $array | %{ $hash[$_] = $hash[$_] + 1 }
   $result = $hash.GetEnumerator() | ?{$_.value -gt 1} | %{$_.key}
   Return $result
}


Cheers!

No comments:

Post a Comment