title: Getting Dynamic Key value from json using Powershell
body: <p>The end goal here is to get the <em>x64.msi</em> download link based on the latest version of the  Nessus Agent. I need a way to get the first Key with &quot;Nessus Agent&quot; string match and then iterate all objects below until a match is found for the value in the <em>file</em> parameter.</p>
  <p>Note, the &quot;&quot;Nessus Agents - 8.2.4&quot; is dynamic as the version number will change over time so this <em>key</em> value cannot be hard coded.</p>
  <p>I am new to Powershell and can't find any examples on how to do this, any help would be great! :)</p>
  <p>example JSON object below:</p>
  <pre class="lang-json prettyprint-override"><code>{
     &quot;releases&quot;:{
        &quot;latest&quot;:{
           &quot;Plugins Archive&quot;:[
              {
                 &quot;file&quot;:&quot;Agent_plugins_expires_2021-05-23.tgz&quot;,
                 &quot;version&quot;:&quot;null&quot;,
                 &quot;size&quot;:585141662,
                 &quot;release_date&quot;:&quot;05/19/2021&quot;,
                 &quot;product_release_date&quot;:&quot;05/19/2021&quot;,
                 &quot;md5&quot;:&quot;d001d04decd3ddc0689590c24cd70b4f&quot;,
                 &quot;sha256&quot;:&quot;a642b52c428b9ffd7214a76de65a895b2b1b863a9156223e7a80561c1538e766&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/Agent_plugins_expires_latest.tgz&quot;
              }
           ],
           &quot;Nessus Agents - 8.2.4&quot;:[
              {
                 &quot;file&quot;:&quot;NessusAgent-8.2.4-amzn.x86_64.rpm&quot;,
                 &quot;version&quot;:&quot;8.2.4&quot;,
                 &quot;size&quot;:17067122,
                 &quot;release_date&quot;:&quot;03/31/2021&quot;,
                 &quot;product_release_date&quot;:&quot;04/08/2021&quot;,
                 &quot;md5&quot;:&quot;00f3d1be5355f256621f9b1241cf0c05&quot;,
                 &quot;sha256&quot;:&quot;5c6c3478e35296331e971278eabeaf693c3691f1ebf734adcae3cfbf6c6c23fa&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-amzn.x86_64.rpm&quot;
              },
              {
                 &quot;file&quot;:&quot;NessusAgent-8.2.4-debian6_amd64.deb&quot;,
                 &quot;version&quot;:&quot;8.2.4&quot;,
                 &quot;size&quot;:16824112,
                 &quot;release_date&quot;:&quot;03/31/2021&quot;,
                 &quot;product_release_date&quot;:&quot;04/08/2021&quot;,
                 &quot;md5&quot;:&quot;c888f6e4ab60b4a2bd85f0b291d44171&quot;,
                 &quot;sha256&quot;:&quot;c3655308cb3adbd1319a6eb77210c4eb2c031f5d2288d9affbc103ea0939f220&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-debian6_amd64.deb&quot;
              },
              {
                 &quot;file&quot;:&quot;NessusAgent-8.2.4-es5.x86_64.rpm&quot;,
                 &quot;version&quot;:&quot;8.2.4&quot;,
                 &quot;size&quot;:19471101,
                 &quot;release_date&quot;:&quot;03/31/2021&quot;,
                 &quot;product_release_date&quot;:&quot;04/08/2021&quot;,
                 &quot;md5&quot;:&quot;c72ca4c47b44067204e394c6d131bb7b&quot;,
                 &quot;sha256&quot;:&quot;06f70cf0fbd5d0622367042550d24c48545f61ea7f0856532ae2efa70475a06f&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-es5.x86_64.rpm&quot;
              },
              {
                 &quot;file&quot;:&quot;NessusAgent-8.2.4-es6.x86_64.rpm&quot;,
                 &quot;version&quot;:&quot;8.2.4&quot;,
                 &quot;size&quot;:19407452,
                 &quot;release_date&quot;:&quot;03/31/2021&quot;,
                 &quot;product_release_date&quot;:&quot;04/08/2021&quot;,
                 &quot;md5&quot;:&quot;3b87ee638758201570adf66cbc369b67&quot;,
                 &quot;sha256&quot;:&quot;56e7c130c38d915332093a287cdab39d402777b69f39afd7e1f476423b477af1&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-es6.x86_64.rpm&quot;
              },
              {
                 &quot;file&quot;:&quot;nessus-agent-updates-8.2.4.tar.gz&quot;,
                 &quot;version&quot;:&quot;8.2.4&quot;,
                 &quot;size&quot;:590396412,
                 &quot;release_date&quot;:&quot;03/31/2021&quot;,
                 &quot;product_release_date&quot;:&quot;04/08/2021&quot;,
                 &quot;md5&quot;:&quot;4348bcf458acfb826c447ff8b5176057&quot;,
                 &quot;sha256&quot;:&quot;0130b16ad01d9e189faaf8f51a9ebf824da69977d39b58e50460a24d2dc480a6&quot;,
                 &quot;file_url&quot;:&quot;https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/nessus-agent-updates-latest.tar.gz&quot;
              }
  </code></pre>
  <p>My code starts with:</p>
  <pre><code>$output = &quot;C:\nessus_releases.json&quot;;
  $jout = Get-Content -Path $output -raw | ConvertFrom-Json;
  </code></pre>
  <p>As a test, if I run the following, it does return the second object under the &quot;Nessus-Agents - 8.2.4&quot; key:</p>
  <pre><code>Write-Output($jout.releases.latest.'Nessus Agents - 8.2.4'.Item(1));
  </code></pre>
  <p>However, trying things like the below to get the <em>key</em> values, doesn't return anything:</p>
  <pre><code>$jout.releases.latest | ForEach-Object {
      Write-Output($_.key);
  };
  </code></pre>
  <p>Also tried the below that again, doesn't return anything:</p>
  <pre><code>$version = $jout.releases.latest | Where-Object {$_ -match &quot;Nessus Agents&quot;}
  Write-Output($version)
  </code></pre>
  <p>UPDATE:</p>
  <p>I think I have a way which seems to work to get the key name:</p>
  <pre><code>$properties = $jout.releases.latest |
  Get-Member -MemberType Properties |
  Select-Object -ExpandProperty Name
  
  $version = $properties | Where-Object {$_ -match &quot;Nessus Agents&quot;}
  
  Write-Output($version)
  </code></pre>
  <p>This returns:</p>
  <pre><code>Nessus Agents - 8.2.4
  </code></pre>