-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-utilityArea - Microsoft.PowerShell.Utility moduleArea - Microsoft.PowerShell.Utility module
Description
It is understandable to expect:
1, 1, 2, 2 | Select-Object -Unique -First 2to return 1, 2, but it actually returns just 1.
The reason is that -Unique is applied after -First 2 has been applied; generally, speaking, -Unique is applied to whatever output the other arguments result in (-First, -Last, -Index, ....), which is worth clarifying.
Workaround: Chain two Select-Object calls:
1, 1, 2, 2 | Select-Object -Unique | Select-Object -First 2As an aside: If Select-Object -Unique were implemented efficiently, this would still preserve the streaming benefits and -First's ability to stop the pipeline on demand, but it currently isn't - see PowerShell/PowerShell#7707
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 1bcdb306-9878-3e1e-887d-07127cf9fd7c
- Version Independent ID: b02a39dc-b661-7dac-4482-276ca3724504
- Content: Select-Object (Microsoft.PowerShell.Utility) - PowerShell
- Content Source: reference/7.1/Microsoft.PowerShell.Utility/Select-Object.md
- Product: powershell
- Technology: powershell-cmdlets
- GitHub Login: @sdwheeler
- Microsoft Alias: sewhee
Metadata
Metadata
Assignees
Labels
area-utilityArea - Microsoft.PowerShell.Utility moduleArea - Microsoft.PowerShell.Utility module