Powershell 2.0 question - Iterating through a hash of hashes generated from import-csv

Answered Powershell 2.0 question - Iterating through a hash of hashes generated from import-csv

  • Thursday, March 07, 2013 11:10 PM
     
     

    I understand how to iterate over a hash and extract key value pairs. 

    This was manageable when dealing with simple binary association but it gets weirder when I import a csv file into a hash with headers.

    The end result is a hash table containing a hash for each line of the imported csv.

    Can someone please give an example of how to iterate over the sub hashes?

    Any help you can provide would be greatly appreciated.

    Thanks,

    Andy

All Replies

  • Friday, March 08, 2013 12:12 AM
    Moderator
     
     Answered Has Code
    $ht = @{
             a = @{a=1;b=2;c=3}
             b = @{d=4;e=5;f=6}
             c = @{g=7;h=8;i=9}
            }
    $ht.Keys | foreach {$ht[$_].GetEnumerator()}


    Name                           Value                                                                                                       
    ----                           -----                                                                                                       
    g                              7                                                                                                           
    i                              9                                                                                                           
    h                              8                                                                                                           
    c                              3                                                                                                           
    a                              1                                                                                                           
    b                              2                                                                                                           
    d                              4                                                                                                           
    e                              5                                                                                                           
    f                              6                                                                                                           



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "