Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-PSUnique enhancement #150

Open
jdhitsolutions opened this issue Jun 8, 2024 Discussed in #149 · 2 comments
Open

Get-PSUnique enhancement #150

jdhitsolutions opened this issue Jun 8, 2024 Discussed in #149 · 2 comments

Comments

@jdhitsolutions
Copy link
Owner

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>
@jdhitsolutions
Copy link
Owner Author

Using a property might also improve how this function handles more complex objects.

@jdhitsolutions
Copy link
Owner Author

I have added this feature to v2.50.0 which has been published to the PowerShell Gallery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant