Working with hash tables. Need help understand

Author Message
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)
0
[Helpful answer received] / [List Solutions Only]
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?
 
#1
    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)
    0
    [This post was marked as helpful]
    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)})
     
    #2
      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)
      0
      Sorry I have just fixed a small bug (I copied and pasted wrong version)
      -join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
       
      #3
        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)
        0
        i have it working! thank you very much!
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9