title: Powershell: Using jQuery through InternetExplorer.Application
body: <p>I followed <a href="http://www.s-anand.net/blog/automating-internet-explorer-with-jquery/" rel="nofollow">this article</a>, explaining how to spice up an Internet Explorer COM-Object with jQuery. While the author used Python, I want to do something similar in Powershell.</p>
  
  <p>Right now I have this code:</p>
  
  <pre><code>function addJQuery ($browser) {
      $url="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"
  
      $document = $browser.document
      $window = $document.parentWindow
      $head = @($document.getElementsByTagName("head"))[0]
      $script = $document.createElement("script")
      $script.type = "text/javascript"
      $script.src = $url
      $head.appendChild($script)
      while (!$window.jQuery) {
          sleep -milliseconds 100
      }
      return $window.jQuery
  }
  
  $ie = New-Object -comobject InternetExplorer.Application
  $ie.visible = $true
  $ie.Navigate("https://some.site.com")
  while ($ie.busy) {start-sleep -milliseconds 500}
  $j = addJQuery $ie
  </code></pre>
  
  <p>With Fiddler and via the document.scripts collection I verified that the file gets downloaded. However, the script sleeps forever and when I try to output $window.jQuery it prints nothing in the Powershell ISE console.</p>
  
  <p>The Script is nevertheless correctly loaded, since jQuery-Functions can be called from the browser's console or via execScript().</p>
  
  <p>It seems the problem is that the DOM-representation available via $ie.document isn't updated when DOM-changes are made via JavaScript. But shouldn't the Internet Explorer COM-Object behave the same way in Powershell as it does in Python?</p>