Skip to content

Get-PSUnique enhancement #150

@jdhitsolutions

Description

@jdhitsolutions

Discussed in #149

Originally posted by scriptingstudio June 8, 2024
Parameter Property makes the function more universal

param (
    [Parameter(Position = 0, Mandatory, ValueFromPipeline)]
    [ValidateNotNullOrEmpty()]
    [object]$InputObject,
    [string[]]$Property
)
...
# process block
if ($Property) {
    foreach ($item in $InputObject) {
        $props = $item.PSObject.Properties.where{$_.name -in $Property}
        if (-not $props) {continue}
        if (-not $UniqueList.Exists({-not (Compare-Object $args[0].PSObject.properties.where{$_.name -in $Property}.value $props.value)})) {
            $UniqueList.add($item)
        }
    }
}
else {
    foreach ($item in $InputObject) {
        if (-not $UniqueList.Exists({-not (Compare-Object $args[0].PSObject.properties.value $item.PSObject.Properties.value)})) {
            $UniqueList.add($item)
        }
    }
}
```</div>

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions