title: Discrepency between getElementById and getElementsByName in Powershell
body: <p>I'm having a problem with Powershell and MSHTML: getElementById and getElementsByTagName are giving me different results.</p>
  
  <p>I have this HTML file:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Moo&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Hello world!&lt;/h1&gt;
          &lt;ul id="a"&gt;
              &lt;li&gt;Bob
              &lt;li&gt;Cat
              &lt;li&gt;Fish
          &lt;/ul&gt;
          &lt;ul id="b"&gt;
              &lt;li&gt;Bob
              &lt;li&gt;Dog
              &lt;li&gt;Cow
          &lt;/ul&gt;
          &lt;div id="x"&gt;
              &lt;b&gt;What's the problem? Don't you &lt;i&gt;like soup&lt;/b&gt; like this?&lt;/i&gt;.
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Yes, it's purposely meant to be badly nested as I'm playing with ideas (and testing for limitations) at the moment.</p>
  
  <p>I'm loading this file into Powershell with MSHTML by doing (from <a href="https://stackoverflow.com/a/24989452/130352">https://stackoverflow.com/a/24989452/130352</a> ):</p>
  
  <pre><code>$html = new-object -ComObject "HTMLFile"
  $source = get-content -path $htmlFileName -raw
  $html.IHtmlDocument2_write($source)
  </code></pre>
  
  <p>If I now do:</p>
  
  <pre><code>$d = $html.getElementById("x")
  $d.TagName
  </code></pre>
  
  <p>I get the expected output (<code>DIV</code>). However if I do:</p>
  
  <pre><code>$d = $html.getElementsByTagName("div")
  $d[0].TagName
  </code></pre>
  
  <p>I get no output. <code>$d.length</code> returns 1. <code>$d[0] | ft</code> spits out all the properties and values without a problem. But accessing properties from $d[0] directly doesn't return anything (i.e., asking for innerText, outerHtml, etc return no data, whilst finding the element by ID (i.e., with <code>getElementById</code>) has no problem and I can access the properties.</p>
  
  <p>Similarly, if I assign to a variable (i.e., <code>$z = $d[0]</code>), and then work directly on $z, I get the same issue.</p>
  
  <p>What am I missing?</p>