I have a file with list of users with duplicate entries. My goal is to process this file and generate the duplicate list. I also need to know how many times a entry got repeated in file incase of duplication. This is the requirement I got today and I could able to fulfill this with less efforts using PowerShell.
So, here is the script.
$hash =@{} $users = Get-Content c:\tempuserslist.txt $users | % {$hash[$_] = $hash[$_] + 1 } $hash.getenumerator() | ? { $_.value -gt 1 }
In above example, I used a hash table to keep track of number of entries of each. We can use arrays here but that won’t help you listing the duplicates count. If you would like read more details about hashes, please refer http://technet.microsoft.com/en-us/library/ee692803.aspx