Home Dashboard Directory Help
Search

sort-object kill array with 1 element by brima


Status: 

Active


1
3
Sign in
to vote
Type: Bug
ID: 774542
Opened: 12/17/2012 5:17:22 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

if you hav a array with only 1 element and sort this with sort-object it destroy the array.
I have a script that list the groups (member of) for AD-User and sort this groups. If the user is only in one group this not work, after the sort-object the array is not longer a array.

PS U:\> $GroupTable = @()
PS U:\> $GroupTable += "group1"
PS U:\> $GroupTable[0]
group1
PS U:\> $GroupTable -is [Array]
True
PS U:\> $GroupTable = $GroupTable | Sort-Object
PS U:\> $GroupTable[0]
g
PS U:\> $GroupTable -is [Array]
False

My workaround for the problem:

PS U:\> $GroupTable = @()
PS U:\> $GroupTable += "group1"
PS U:\> $GroupTable[0]
group1
PS U:\> $GroupTable -is [Array]
True
PS U:\> [array]$GroupTable = $GroupTable | Sort-Object
PS U:\> $GroupTable[0]
group1
PS U:\> $GroupTable -is [Array]
True
Details
Sign in to post a comment.
Posted by PetSerAl on 1/15/2013 at 8:44 PM
It not Sort-Object fault, it is how PowerShell pipeline works.
Sign in to post a workaround.