I have a PowerShell script that fails if only 1 string is fed to an array because it splits it into characters when using Get-Unique and/or Sort-Object. However, if multiple values are provided then it works as expected. So for example:
Expected behavior:
PS X:\> $t = @("asd","bcd") | Get-Unique
PS X:\> $t[0]
asd
PS X:\> $t[1]
bcd
Unexpected (with 1 value):
PS X:\> $t = @("asd") | Get-Unique
PS X:\> $t[0]
a
PS X:\> $t[1]
s
PS X:\> $t[2]
d
Could someone explain why this is happening and how to prevent it? I'd appreciate any input as my searches did not bring any luck.
Thanks