hal07
-
Total Posts
:
19
- Scores: 0
-
Reward points
:
0
- Joined: 5/1/2011
- Location: Bergen, Norway
-
Status: offline
|
Working with hash tables. Need help understand
Wednesday, June 22, 2011 7:38 PM
( permalink)
So I traverse and I want to make some sort of table or similar with the following info: Name, Phone number, Department $hash = @{} foreach ($item in $collection) { $hash.add( $item.name, $item.phone, $item.department ) { However this will not work, as hashtables can only be 2-dimentional array-like.. How do I go from here to solve my problem? After this, I want to sort all items in the $hash by first department and then alphabetically by name.. How do I do that?
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Working with hash tables. Need help understand
Wednesday, June 22, 2011 10:43 PM
( permalink)
I am not sure where you are getting your data so I decided to do an example with data from AD using Quest cmdlets. I would make a custom object and put it in an array and then use the sort.object cmdlet $Users = @()
Get-QADUser | foreach {
$myObj = "" | Select Department, Name, Phone
$myObj.Name = $_.Name
$myObj.Phone = $_.PhoneNumber
$myObj.Department = $_.Department
$Users += $myObj
}
$Users | Sort-Object Department, Name
Tested this and it works like you described.
<message edited by TomRiddle on Thursday, June 23, 2011 12:41 AM>
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Working with hash tables. Need help understand
Thursday, June 23, 2011 12:44 AM
( permalink)
Sorry I have just fixed a small bug (I copied and pasted wrong version)
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
hal07
-
Total Posts
:
19
- Scores: 0
-
Reward points
:
0
- Joined: 5/1/2011
- Location: Bergen, Norway
-
Status: offline
|
Re:Working with hash tables. Need help understand
Thursday, June 23, 2011 1:00 AM
( permalink)
i have it working! thank you very much!
|
|
|
|