locked
read key value pair from a powershell using foreach loop or hashtable ? RRS feed

  • Question

  • hi,

     i would like to write a script which loop through few keys and for these  i have few values .how can i read  these values for these keys?

    assume i have this 

    $states = @{"Washington" = "Olympia"; "Oregon" = "Salem"; California = "Sacramento"}

    now how can i do a foreach loop here and i can get the values for each key

    something like:

    foreach($mykey in $states)

    {

    $myvalue = value of mykey

    # apply $myvalue for further processing

    }


    Das



    • Edited by DADasRF Friday, January 2, 2015 7:32 AM
    Friday, January 2, 2015 7:05 AM

Answers

  • Use 

    $States.getenumerator()


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

    • Marked as answer by DADasRF Monday, January 5, 2015 5:48 AM
    Friday, January 2, 2015 11:58 AM

All replies