internet explorer 9 - PowerShell IE9 ComObject has all null properties after navigating to webpage -


i have powershell script navigates (presumably) classic asp page on our intranet stop windows service running on our server part of deployment process service (and restarts after deploying new files). ran fine until upgraded ie9. here's script.

# open service page in ie $ie = new-object -comobject internetexplorer.application $ie.visible = $true $ie.navigate($serviceurl) while($ie.busy) { start-sleep 1 }  # stop service $ie.document.getelementbyid("dropdownactionlist").value = "stop" $ie.document.getelementbyid("buttontakeaction").click() while($ie.busy) { start-sleep 1 } 

now when run script, launches ie, throws following error:

you cannot call method on null-valued expression. @ c:\projects\abc\scripts\deploy.ps1:85 char:28 + $ie.document.getelementbyid <<<< ("dropdownactionlist").value = "stop"     + categoryinfo          : invalidoperation: (getelementbyid:string) [], runtimeexception     + fullyqualifiederrorid : invokemethodonnull 

when investigate in powershell, find if create ie comobject, @ first has valid properties, navigate the service control page, properties null (almost if comobject gone away?). example, before hwnd property had valid value, it's null ($ie.hwnd -eq $null returns true). no error displayed in powershell when navigate page.

i looked @ similar questions, first 1 doesn't match circumstance (the document property null in case) , latter one, ie9 defaults compatibility mode intranet sites. saved asp page , ran through w3c validator , threw errors (although none related elements i'm trying deal with). unfortunately can't fix those. other sites don't seem have problem. suspicions on problem may , recommendations on work-arounds?

i worked through this.. sort of. seeing same behavior until turned off protected mode in ie. seems have submitting 1 security zone next. so.. assuming original page in internet zone, protected mode on, submit page in trusted zone or intranet or whatever, seems com context lost. intentional. i'm going try fixing zones, , keeping protected mode on.

hope helps.

edit: non-issue if run powershell in elevated mode (run admin)


Comments