Created
April 11, 2016 19:38
-
-
Save sean-m/82dc9dbb5c0ad56047144cf739f08734 to your computer and use it in GitHub Desktop.
Non optimal, quick hack when sort -unique and select -unique didn't do what I want.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Dedupe { | |
param ( | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$true, | |
ValueFromPipelinebyPropertyName=$false, | |
Position=0)] | |
$obj, | |
[Parameter(Mandatory=$true, | |
ValueFromPipeline=$false, | |
ValueFromPipelinebyPropertyName=$false, | |
Position=1)] | |
$property | |
) | |
begin { | |
$uniq = @{} | |
} | |
process { | |
$val = $obj.$property | |
if ($uniq.ContainsKey($val)) { | |
# skip | |
} | |
else { | |
$uniq.Add($val, "") | |
$obj | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment