title: Selecting XML node using powershell with Where clause
body: <p>I have the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;video publishState="Published" xmlns="urn:schemas-microsoft-com:msnvideo:catalog"&gt;
  &lt;uuid&gt;ed255a56e807&lt;/uuid&gt;
  &lt;title&gt;ABCD&lt;/title&gt;
  &lt;description&gt;ABCD&lt;/description&gt;
  &lt;startDate&gt;2014-06-12T06:30:00Z&lt;/startDate&gt;
  &lt;activeEndDate&gt;2017-06-01&lt;/activeEndDate&gt;
  &lt;searchableEndDate&gt;2017-06-01&lt;/searchableEndDate&gt;
  &lt;archiveEndDate&gt;2019-05-22&lt;/archiveEndDate&gt;
  
  &lt;videoFiles&gt;
  
  &lt;videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="400" width="320" height="180" fileSize="9654368" msnFileId="ED0ADD1E-7C36-472E-8186-5C43DDCCD58C" formatCode="101"&gt;
  
  &lt;uri&gt;http://e2/ds/977d13e5-285f-4fe3-b49c-a6b604e89c22.mp4&lt;/uri&gt;
  
  &lt;/videoFile&gt;
  
  &lt;videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="600" width="640" height="360" fileSize="14911095" msnFileId="59AB7AE5-15F3-4EA8-ABD9-92E1A1CE0424" formatCode="102"&gt;
  
  &lt;uri&gt;http://e2/ds/0aaad23d-bcb1-48e4-85c7-788b58ab8ae6/ds/3f4b77a3-3157-48a4-88b5-df854025cfe5.mp4&lt;/uri&gt;
  
  &lt;/videoFile&gt;
  
  &lt;videoFile msnFileId="EDAA3798-B16B-435F-A9CA-6B1D07729D44" formatCode="1001" fileHash="ebc2f23aba9f0ff8d0146a052089a34f"&gt;
  
  &lt;uri&gt;ftp://handler_20140611_highlight_b_222747.mp4&lt;/uri&gt;
  
  &lt;/videoFile&gt;
  
  &lt;videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="3000" width="1280" height="720" fileSize="70668740" msnFileId="9505AEF2-7742-4BB1-9427-F07185D6FC9B" formatCode="104"&gt;
  
  &lt;uri&gt;http://e2/ds/a2e1563f-c9a3-41f7-97fe-e024742c6bbf.mp4&lt;/uri&gt;
  
  &lt;/videoFiles&gt;
  
  &lt;/video&gt;
  </code></pre>
  
  <p>I am trying to get URI value where <code>formatCode="1001"</code>. However since its an array, I am unable to do so. On getting to <code>formatCode =1001</code> all values of array <code>$uri</code> are printed on console. I have tried piping Where clause e.g <code>| Where {$xml.video.videoFiles.videoFile.formatCode -eq 1001 }</code> but that too didn't help.</p>
  
  <p>I am using the following code:</p>
  
  <pre><code>Get-ChildItem D:\video*.xml | ForEach-Object 
  { 
      $xml = [xml] (Get-Content $_.fullname)
      # $xml.video.videoFiles.videoFile | Where-Object { $_.formatCode -eq 1001 } | Format-Table   msnFileId, uri      
      $out = New-Object PSObject
      $out | Add-Member NoteProperty UUID -Value $xml.video.uuid.innertext
      $out | Add-Member NoteProperty EndDate -Value $xml.video.activeEndDate
      Foreach ($uri in $xml.video.videoFiles.videoFile.uri)
      {
          if ($xml.video.videoFiles.videoFile.formatCode -eq 1001)
          {
              $temp1 = [string]$uri
          }
      }
      $out | Add-Member NoteProperty URI -Value $temp1
      Write-Output $out
  }
  </code></pre>