title: Find ONLY HTML Files & Replace Markup Within Them, in PowerShell
body: <p>I need to write up a script in PowerShell that will search through a folder, find ONLY HTML files, and replace a certain line of markup that I specify with new markup.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>$filePath = 'C:\Users\bettiom\Desktop\schools\alex\Academics'
  $processFiles = Get-ChildItem -Exclude *.bak -Filter *.htm -Recurse -Path $filePath
  
  $query = '&lt;html&gt;'
  $replace = '&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;'
  
  foreach ( $file in  $processFiles ) {
       $file | Copy-Item -Destination "$file.bak"
  
      $arrayData = Get-Content $file
      for ($i=0; $i -lt $arrayData.Count; $i++) {
           if ( $arrayData[$i] -match $query ) {
                $arrayData[$i+1] = $arrayData[$i+1].Replace($query,$replace)
           } else { }
      }
      $arrayData | Out-File $file -Force
  }
  </code></pre>
  
  <p>Everything seems to work up until the foreach loop, it then just doesn't execute pass that line.</p>
  
  <p>Any help given will be much appreciated.</p>
  
  <p>Thanks in Advance.</p>