title: Powershell ConvertFrom-Json: Selecting Value of Nested Array Based on Property Name
body: <p>I have a json file that I'm trying to export to csv using powershell, but I only need certain nested values.  It looks like the following:</p>
  <pre><code>[
     {
        &quot;ItemName&quot;: &quot;A&quot;,
        &quot;ItemID&quot;: &quot;I001&quot;,
        &quot;ItemDate&quot;: &quot;2021-03-01&quot;,
        &quot;ItemValue&quot;: &quot;1000&quot;,
        &quot;ItemTags&quot;: [
           {
              &quot;Name&quot;: &quot;First tag name&quot;,
              &quot;Value&quot;: &quot;medium&quot;
           },
           {
              &quot;Name&quot;: &quot;Another tag name&quot;,
              &quot;Value&quot;: &quot;red&quot;
           },
           {
              &quot;Name&quot;: &quot;Tag 3&quot;,
              &quot;Value&quot;: null
           },
           {
              &quot;Name&quot;: &quot;Tag 4&quot;,
              &quot;Value&quot;: &quot;Yes&quot;
           }
        ]
     },
     {
        &quot;ItemName&quot;: &quot;B&quot;,
        &quot;ItemID&quot;: &quot;I002&quot;,
        &quot;ItemDate&quot;: &quot;2021-02-01&quot;,
        &quot;ItemValue&quot;: &quot;3000&quot;,
        &quot;ItemTags&quot;: [
           {
              &quot;Name&quot;: &quot;First tag name&quot;,
              &quot;Value&quot;: &quot;best&quot;
           },
           {
              &quot;Name&quot;: &quot;Another tag name&quot;,
              &quot;Value&quot;: &quot;green&quot;
           },
           {
              &quot;Name&quot;: &quot;Tag 3&quot;,
              &quot;Value&quot;: null
           },
           {
              &quot;Name&quot;: &quot;Tag 4&quot;,
              &quot;Value&quot;: &quot;No&quot;
           }
        ]
     }
  ]
  </code></pre>
  <p>The nested &quot;ItemTags&quot; portion is where I'm having trouble.  The actual json file has dozens of Item Tags and ordering of them can vary so what I'd like to do is only select ones based on the &quot;Name&quot; of the ItemTag, for example select the ItemTag Value where ItemTag Name is Tag 4.</p>
  <p>I've only been able to do it based on the order like this:</p>
  <pre><code>
  $obj1 = Get-Content -Path &quot;C:\Temp\sample.json&quot;  | ConvertFrom-Json
  $obj1 | select ItemName, ItemID, ItemDate, ItemValue, @{Name = 'Tag 4'; Expression ={$_.ItemTags[3].Value}} | Export-CSV &quot;C:\Temp\items.csv&quot; -NoTypeInformation
  </code></pre>
  <p>But again, because the ItemTags ordering can be different from one day to the next, this won't quite do it.  How would I modify this to select based on the ItemTag Name of &quot;Tag 4&quot;?</p>