powershell and IE11

I have two systems that are identical.  When I run the following code in powershell.  The Document is mshtml.HTMLDocumentClass.  But when I run the same code on the other system.  The Document is System.__ComObject.

Why is the Document different on the other system.  When I try to do a getelementbyID.  It works when the document is of type mshtml.HTMLDocumentClass.  But it fails when document is of type System.__ComObject. 

I have the same version of IE version 11.  The same version of powershell version 3.0.

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://localhost:8129/default.aspx")
$ie

Application          : System.__ComObject
Parent               : System.__ComObject
Container            :
Document             : mshtml.HTMLDocumentClass
TopLevelContainer    : True
Type                 : HTML Document
Left                 : 125
Top                  : 47
Width                : 1701
Height               : 984
LocationName         : Beyond TV
LocationURL          : http://localhost:8129/default.aspx
Busy                 : False
Name                 : Internet Explorer
HWND                 : 4392126
FullName             : C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
Path                 : C:\Program Files (x86)\Internet Explorer\
Visible              : False
StatusBar            : True
StatusText           :
ToolBar              : 1
MenuBar              : True
FullScreen           : False
ReadyState           : 4
Offline              : False
Silent               : False
RegisterAsBrowser    : False
RegisterAsDropTarget : True
TheaterMode          : False
AddressBar           : True
Resizable            : True $ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://localhost:8129/default.aspx")
$ie

Application          : System.__ComObject
Parent               : System.__ComObject
Container            :
Document             : System.__ComObject
TopLevelContainer    : True
Type                 : HTML Document
Left                 : 397
Top                  : 307
Width                : 1200
Height               : 674
LocationName         : Beyond TV
LocationURL          : http://localhost:8129/default.aspx
Busy                 : False
Name                 : Internet Explorer
HWND                 : 1116142
FullName             : C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
Path                 : C:\Program Files (x86)\Internet Explorer\
Visible              : False
StatusBar            : False
StatusText           :
ToolBar              : 1
MenuBar              : True
FullScreen           : False
ReadyState           : 4
Offline              : False
Silent               : False
RegisterAsBrowser    : False
RegisterAsDropTarget : True
TheaterMode          : False
AddressBar           : True
Resizable            : True

February 8th, 2015 11:51am

Different versions of PowerShell.

Free Windows Admin Tool Kit Click here and download it now
February 8th, 2015 12:26pm

Both are 3.0 .  I did a $PSVersionTable.

The Buildversion is 6.2.9200.16398 on the failing system. and 6.2.92...16481

The two systems were installed at the same time with Windows 7 pro.  They were both up todate on patches.  The failing system started failing sometime during the summer of 2014.  I've seen other people with the same problem but no fix.

RAC

February 8th, 2015 8:49pm

Clearly they are both different.
Free Windows Admin Tool Kit Click here and download it now
February 8th, 2015 10:08pm

I upgraded to powershell 4.0 and still have the problem.
February 10th, 2015 11:52pm

I upgraded to powershell 4.0 and still have the problem.

You are missing net framework updates or you need to repair the framework.

Be sure the SPs for thje frameworks are installed.

Free Windows Admin Tool Kit Click here and download it now
February 10th, 2015 11:56pm

I have .net framework 4.5.2 installed.  I ran netfx_setupverifier.  It said that everything was fine.

I can't fine any sp for 4.5.2

RAC

February 12th, 2015 2:58am

I have the same Problem.

$HTMLDOM = new-object -com "HTMLFILE"

At the System with installed Office:

$HTMLDOM.PsTypeNames
mshtml.HTMLDocumentClass
System.__ComObject#{3050f55f-98b5-11cf-bb82-00aa00bdce0b}
System.__ComObject
System.MarshalByRefObject
System.Object

At the System without installed Office:

$HTMLDOM.PsTypeNames
System.__ComObject#{3050f55f-98b5-11cf-bb82-00aa00bdce0b}
System.__ComObject
System.MarshalByRefObject
System.Object

The registry key has the right settings. -> http://blogs.msdn.com/b/powershell/archive/2006/09/10/controlling-internet-explorer-object-from-powershell.aspx

"If the htmlfile progid has the following settings in the registry:

HKEY_CLASSES_ROOT\CLSID\{25336920-03F9-11CF-8FD0-00AA00686F13}\InProcServer32

Class        : mshtml.HTMLDocumentClass
Assembly  : Microsoft.mshtml, Version=7.0.3300.0,  Culture=neutral,       PublicKeyToken=b03f5f7f11d50a3a

then, mshtml.htmldocumentclass become .NET wrapper for the document.body object."

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 2:09am

I think I had Office installed on both machines and uninstalled it on the machine that is failing.  I will try to install Office later and see if it fixes the problem.

But in the mean time I have found a work around for my problem at:

https://teusje.wordpress.com/2012/12/29/web-scraping-with-powershell/

It allows me to do what I want to do in 2 lines of code rather than about 12 lines.

RAC

February 13th, 2015 5:40pm

I know but you need minimum powershell version 3.0, UTF-8 encoded content will not work, login with session cookies are not supported, etc...
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 9:50pm

I know but you need minimum powershell version 3.0, UTF-8 encoded content will not work, login with session cookies are not supported, etc...

That is the minimum version currently.  WS2008 and earlier use V2 but that is now going out of support. Only V3 and later sill be useful.

February 13th, 2015 10:02pm

I installed office 2003 word.  This did not fix the problem. The code below is my fix to the problem. 

$site = Invoke-WebRequest -UseBasicParsing -Uri http://localhost:8129/default.aspx
$b=$site.Rawcontent.contains("Currently Recording")

I see that you are trying to open an HTMLFile.  So I tried the following:

$site = Invoke-WebRequest -UseBasicParsing -Uri "U:\macaddress.html"

$site.RawContent contained the data that was in the file.

Hope this helps.

RAC

  • Marked as answer by rac8006 Friday, February 13, 2015 7:52 PM
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 10:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics