Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Difference of Sort-Object -Unique, Sort-Object | Get-Unique, and Select-Object -Unique

If you want to uniq a list in PowerShell, there is more than one way to do it and these are slightly different.

# Cmdlets Sort-Object -Unique Sort-Object | Get-Unique Select-Object -Unique
1 Sort elements Yes Yes No
2 Case sensitive in dedupe Case Insensitive Case Sensitive Case Sensitive
3 Case sensitive in sort Case Insensitive Case Insensitive Case Insensitive
4 Has -CaseSensitive option Yes No No
5 Case sensitive in dedupe with -CaseSensitive option Case Sensitive - -
6 Case sensitive in sort with -CaseSensitive option Case Sensitive - -
7 Can sort in case-sensitive alphabetical order No No -
8 Can specify dedupe key with code block Yes No No