Getting the current hash key in a ForEach-Object loop in powershell

前端 未结 3 1273
生来不讨喜
生来不讨喜 2021-02-07 10:37

I\'ve got a hash table:

$myHash = @{ 
   \"key1\" = @{
       \"Entry 1\" = \"one\"
       \"Entry 2\" = \"two\"
   }
            


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-07 11:15

    You can also do this without a variable

    @{
      'foo' = 222
      'bar' = 333
      'baz' = 444
      'qux' = 555
    } | % getEnumerator | % {
      $_.key
      $_.value
    }
    

提交回复
热议问题