powershell - Remove duplicates from beginning of array -
similar removing duplicate values powershell array want remove elements array. issue is, actively work end of array want keep last instance of duplicate. | select -uniq
removes duplicates come after in array.
example (taken above link modified little bit):
$a = @(1,2,5,3,0,4,5,6,2,7,8,9,0) $a = $a | select -uniq
output $a:
1,2,5,3,0,4,6,7,8,9
but desired output i'm looking for:
1,3,4,5,6,2,7,8,9,0
essentially want leave last instance of duplicate.
thank you!
one option reverse array select -unique
working in reverse, reverse result normalize it.
$a = @(1,2,5,3,0,4,5,6,2,7,8,9,0) [array]::reverse($a) $a = $a | select -unique [array]::reverse($a) $a -join ',' 1,3,4,5,6,2,7,8,9,0
Comments
Post a Comment