Skip to content

Instantly share code, notes, and snippets.

@sean-m
Created April 11, 2016 19:38
Show Gist options
  • Save sean-m/82dc9dbb5c0ad56047144cf739f08734 to your computer and use it in GitHub Desktop.
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.
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