Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Find Duplicates In An Array Using PowerShell
WhatsApp
Manpreet Singh
8y
48.6
k
0
2
25
Blog
Welcome to an article where we will find the duplicates in an array. Sometimes, we need to clean the array and get the duplicate values. Here, I have a simple script for you to run with minimal inputs from your end to identify the duplicates on your array.
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.
Duplicates In Array
Windows PowerShell
People also reading
Membership not found