title: PowerShell internet explorer automation error server 2012
body: <p>I have a PowerShell script that logs into one of our sites, clicks some links then closes. Basically just to monitor and make sure everything works ok! below is a snippet from the top of the script.</p>
  
  <pre><code>$ie = new-object -com "InternetExplorer.Application"
  $ie.visible = $true
  $ie.navigate($url)
  while( $ie.busy){Start-Sleep 1} 
  $doc = $ie.document
  $continue = $doc.getElementByID("overridelink")
  $continue.click()
  while( $ie.busy){Start-Sleep 1} 
  </code></pre>
  
  <p>Basically this section opens IE and clicks continue button for certificate error. If i run this on my windows 7 machine it works fine, however on Server 2012 R2 i get:</p>
  
  <p><em>"You cannot call a method on a null-valued expression"</em></p>
  
  <p>Both desktop and server are running PowerShell 4.0 and Internet explorer 11.</p>
  
  <p>I read something a while back that mentioned this may be a bug in 2012 where it doesn't allow this method to click links in IE but cant remember where and if there was a fix!</p>
  
  <p>Does anyone know what causes this and maybe how to resolve it?</p>
  
  <p>another thing i was thinking(if anyone can be bothered to explain!), should i be using invoke-webrequest instead? if so is it possible to log into a site, open some links(doesn't have to be visible on screen) then close confirming it all works?</p>
  
  <p>Thanks in advance for any input!  </p>