07-21-2023, 04:39 PM
In case you want to be fully bombproof, this is what I would advise:
@('Apples', 'Apples ', 'APPLES', 'Banana') |
Sort-Object -Property @{Expression={$_.Trim()}} -Unique
**Output:**
Apples
Banana
This uses the `Property` parameter to first `Trim()` the strings, so extra spaces are removed and then selects only the `-Unique` values.
More info on `Sort-Object`:
Get-Help Sort-Object -ShowWindow
@('Apples', 'Apples ', 'APPLES', 'Banana') |
Sort-Object -Property @{Expression={$_.Trim()}} -Unique
**Output:**
Apples
Banana
This uses the `Property` parameter to first `Trim()` the strings, so extra spaces are removed and then selects only the `-Unique` values.
More info on `Sort-Object`:
Get-Help Sort-Object -ShowWindow