3

I wrote a script to parse a HTML file. I have three machines, Windows 8.1, Windows Server 2012, and Windows Server 2008.

I use the COM object and method $ie.Document.getElementById() to get element in HTML file. The script runs without any problem in Windows 8.1, but is not working in Windows Server 2012 and Windows Server 2008. It shows $ie.Document is null object.

I searched for a while and found that there is a bug with COM object. So I imported manually Microsoft.mshtml.dll, now script runs well in win server 2012, but still not working under win server 2008. I can see all properties by using $ie.document | Get-Member, but the object $ie.Document is always null.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
hawarden_
  • 1,904
  • 5
  • 28
  • 48
  • 1
    Did you check that MS Server 2008 is running the same version of Powershell? (use `$PSVersionTable` or `Get-Host` to test that) – LinkBerest Jun 30 '15 at 17:58
  • @JGreenwell My Powershell is at version 2.0, and I cannot upgrade it because the server holds all website traffic and cannot be stopped. I'm confused because by adding the dll library it should work. – hawarden_ Jul 01 '15 at 07:38
  • GetElementbyId seems not to have a problem with Powershell 2.0 and IE 9+ (tried a working script using `powershell ./testscript.ps1 -version '2.0'` and got that same error: See [this question for a possible workaround on 2.0](https://stackoverflow.com/questions/12733143/powershell-system-comobject-document-property-no-longer-works-under-ie-9) – LinkBerest Jul 02 '15 at 21:31

1 Answers1

0

Take a look at this question. There is some sort of a bug in IE. Installing office fixed this problem for me. YMMV.

Community
  • 1
  • 1
It-Z
  • 1,961
  • 1
  • 23
  • 33