Let’s see how can we do it.
Steps
- Open Windows PowerShell Modules as an administrator.

- Paste the code, mentioned below as .ps1 file and execute it.
- #Add the PowerShell snap in code
- Add - PSSnapIn Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue | Out - Null
- $ht = @ {}
- $Array | foreach {
- $ht["$_"] += 1
- }
- $ht.keys | where {
- $ht["$_"] - gt 1
- } | foreach {
- write - host "Duplicate found $_"
- $newarray += $_
- }
- foreach($obj in $newarray) {
- foreach($term in $terms) {
- if ($term.Labels[1].Value - eq $obj) {
- $emailarray += $term.Name
- write - host $emailarray
- }
- }
Pre-Requisites
- $Array
Assign the array having duplicate values, where you want to find the duplicate values. The script, mentioned above, will compare the array and find duplicates and results with them in the $emailarray as an output.
The script is so quick that it will hardly take any effort and time.

UpMyTech.comPosted Nov 24, 2020, 11:39 AM
This script is not quick if you're dealing with very large arrays (10s of thousands of records +). Using the += method in a foreach is extremely inefficient. Look up "[System.Collections.ArrayList]". Instantiating an array as an arraylist is quite easy. Rather than "$array = @()", simply use "$array=[System.Collections.ArrayList]@()". Now you can use something like "[void]$array.add([PSCUSTOMOBJECT]@{Name=$obj.name;Address=$obj.address})" in a foreach. This is exponentially faster than the += method. If you have more than 100k records to parse through, then this will be 1000s of times faster.