title: Powershell select HTML text
body: <p>I have the following powershell script to open multiple HTML files on multiple computers to extract licensing information.  Looking for some help extracting the innertext elements of <code>&lt;td&gt;</code> where <code>id=2</code>. </p>
  
  <p>Looking to extract for:</p>
  
  <p><em>Product, Serial number,Product Key, Request code</em></p>
  
  <pre><code>ForEach ($system in (Get-Content C:\temp\computers.txt)) {
    $folder = "\\$system\c`$\ProgramData\Autodesk\AdLM\"
    Get-ChildItem $folder *.html  |
    ForEach-Object {
      # Get current filename without .html
      $c = $_.BaseName
      # Create new Internet Explorer Object
      $ie=New-Object -ComObject InternetExplorer.Application
      # $_ (dollar underscore) 'THIS' token. Typically refers to the item inside a foreach loop. Open current HTML file.
      $ie.Navigate("$_")
      while ($ie.busy -eq $true) {
        Start-Sleep -Milliseconds 500
      }
  
      $doc=$ie.Document
      $tables=$doc.getElementsByTagName('table')
       foreach ($table in $tables) {
          if ($div.innertext -match "Product: ") 
          if ($div.innertext -match "Serial number: ")
          if ($div.innertext -match "Product Key: ")
          if ($div.innertext -match "Request code: ")
      }
      $elements.innerText | ForEach-Object { Add-Content -path c:\temp\results.csv "$c,$system,$para1" }
    }
  }
  </code></pre>
  
  <p>Example of the HTML file</p>
  
  <pre><code>&lt;table width="100%" cellspacing=0 cellpadding=0&gt;
      &lt;tr&gt;&lt;td align=left id=1 width=15%&gt;Product:&lt;/td&gt;&lt;td align=left id=2 width=35%&gt;&lt;!--PREVINFO_START--&gt;Autodesk Building Design Suite Premium 2016&lt;!--PREVINFO_END--&gt;&lt;/td&gt;&lt;td align=left id=1&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=left id=2&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td align=left id=1 width=15%&gt;Serial number:&lt;/td&gt;&lt;td align=left id=2&gt;&lt;!--PREVINFO_START--&gt;999-9999999&lt;!--PREVINFO_END--&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;table width="100%" cellspacing=0 cellpadding=0&gt;
      &lt;tr&gt;&lt;td align=left id=1 width=15%&gt;Product key:&lt;/td&gt;&lt;td align=left id=2&gt;424242&lt;/td&gt;&lt;td align=left id=1&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=left id=2&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;table width="100%" cellspacing=0 cellpadding=0&gt;
      &lt;tr&gt;&lt;td align=left id=1 width=15%&gt;Request code:&lt;/td&gt;&lt;td align=left id=3 style='word-break:break-all'&gt;7777 7777 7777 7777&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td align=left id=1&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=left id=3 style='word-break:break-all'&gt;7777 7777 7777 7777&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>