Greg
Greg

Reputation: 152

Can't use InternetExplorer.Application object?

I have an entire code file that works flawlessly on a PC. I brought it over to another one, and it busted. I used this snippet, and the output is just blank, it's not getting anything from the object. The browser does load the page though.

# Create the IE com object 
"Lauching IE process..."
$ie = new-object -com InternetExplorer.Application 
$ie.visible = $true
# Navigate to the login page
"Opening $loginPage"
$ie.navigate($loginPage) 
"Waiting for page to load..."
# Wait for the page to finish loading 
do {sleep 2} until (-not ($ie.Busy)) 
sleep 2
$ie.document.body.innerHTML

I found some references to IE security models, running as Admin, etc, and fiddled with it a bit.

Still no luck.

Any suggestions?

Thanks!

Upvotes: 1

Views: 2982

Answers (2)

Greg
Greg

Reputation: 152

Okay I ended up solving the issue. Based on this post :

Powershell System.__ComObject.document property no longer works under IE 9

I also noticed that

$ie.document | Get-Member

Showed a COM object guid on the broken machine, and mshtml on the good machine. The good machine did indeed have Office installed. I copied

C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\microsoft.mshtml.dll

to the broken machine. Then at the top of my script I added

Add-Type -Path "C:\dll\Microsoft.mshtml.dll"

And bingo, the script now works as expected!

Upvotes: 4

lytledw
lytledw

Reputation: 181

I'm not sure what you have stored inside of your $loginPage variable, so i replaced it with www.google.com and it opened the page, but did not display the .document.body.html portion.

I found this a forum that discussed a similar issue to what you are describing. They recommended changing the code to

$ie = new-object -com internetexplorer.application 
$ie.Visible = $true
$ie.navigate('https://www.google.com')
while($ie.busy){Start-Sleep -Milliseconds 100}
$ie.document.body | select innerhtml

I tried this and it worked fine.

reference: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/2faea229-a114-4d58-9624-f1ee42404928/powershell-internetexplorerapplication-things-are-missing?forum=ITCG

Upvotes: 0

Related Questions