Remove duplicates in a powershell array

Execute the script to remove duplicates in a powershell array. Supply the powershell array as parameter.

Script

<#
.SYNOPSIS
This script can be used to remove duplicates in a powershell array
.DESCRIPTION
This script can be used to remove duplicates in a powershell array
.EXAMPLE
C:\PS> C:\Script\Remove_Duplicates_In_Powershell_Array.ps1 1 1 2 2 3 3 4 4 1 2 3 4
Removes duplicates and displays the output
#>
#use -uniq to remove duplicates from an array.

echo “Array with duplicates”
Write-Host “$args”
$args = $args | select -uniq
echo “Array with duplicates removed”
Write-Host “$args”

 

Output
remove

Leave a Reply