title: Extract Value from JSON Object at run time
body: <p>I am new to PowerShell am I am trying to figure out how to iterate over JSON objects in PowerShell and extract values.</p>
  
  <p>I have a JSON object in a file WIMS.JSON  </p>
  
  <pre><code>{ WIMS:{
      A:{drive:"A"},
      B:{drive:"Z"}
  }}
  </code></pre>
  
  <p>I want to iterate over the objects in WIMS, ie A and B and select the different drive letter in a loop.</p>
  
  <p>I have been able to work out how to get the object names (probably ugly) using </p>
  
  <pre><code>$json = (Get-Content "WIMS.json" -Raw) | ConvertFrom-Json
  $WIMS = $json.WIMS
  $wimNames=$($WIMS| Get-Member -MemberType *Property).Name 
  for ($i=0; $i -lt $wimNames.count; $i++) {
      write-host ("Property names are: " + $wimNames[$i])
      $object=$WIMS| select $wimNames[$i]   #does not work
      $object.drive  #does not work
  }
  </code></pre>
  
  <p>But I am unable to figure out how to extract the objects so I can access the fields.</p>
  
  <p>Any pointers would be most appreciated.</p>