PowerShell Script to Control IE

I have a script that we need to use on our domain to control a login for IE. However, I have it running just fine on a standalone Windows 8.1 machine but cannot get it to run on a domain Windows 8.1 machine.

I've scaled back to the script to an example just for testing purposes:

$URL = "https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate($URL)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.Document.getElementById("Email").value = "asdf"



All this should do is open IE and enter "asdf"as the username.

On the domain computer, this is the error that PowerShell gives us:


Method invocation failed because [System.__ComObject] does not contain a method named 'getElementById'.
At line:7 char:1
+ $ie.Document.getElementById("Email").value = "asdf"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound



I've tried to run the script as an admin (elevated), disabled protected mode, and various combinations of the two but cannot figure out what is holding this up.

Any suggestions would be quite welcome!



Maybe a web proxy sends a different type of page as reply? Check what you get back as object in $ie.Document on your domain PC. You can issue a $Ie.Document | gm and/or dump $je,Document and/or $ie.Document.MimeType and compare.



Maybe a web proxy sends a different type of page as reply? Check what you get back as object in $ie.Document on your domain PC. You can issue a $Ie.Document | gm and/or dump $je,Document and/or $ie.Document.MimeType and compare.



Thanks for the speedy reply.

I followed your suggestion and got radically different results. On the domain PC, running just the $ie.Document got me this:

System.__ComObject


Running it on the non-domain computer I got quite a listing of objects (207 in all) which I would imagine is what I should be getting. (I won't post them unless you need.)

Trying to run the $ie.Document.MimeType results got nothing on the domain, but the non-domain results in "Chrome HTML Document". (My default browser is Chrome despite this script using IE.)



That is worse than expected. Obviously you get an empty COM object. The non-domain result is how it should be (no need to post it).
What happens if you display the web page (in IE) manually? You can use the dev tools too (F12) to analyze the resulting HTML code.



The webpage works fine otherwise.

F12 on the domain looks correct:



Is PowerShell running elevated?

Share this

Related Posts

There was an error in this gadget