问题
I have a PowerShell script that logs into one of our sites, clicks some links then closes. Basically just to monitor and make sure everything works ok! below is a snippet from the top of the script.
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($url)
while( $ie.busy){Start-Sleep 1}
$doc = $ie.document
$continue = $doc.getElementByID("overridelink")
$continue.click()
while( $ie.busy){Start-Sleep 1}
Basically this section opens IE and clicks continue button for certificate error. If i run this on my windows 7 machine it works fine, however on Server 2012 R2 i get:
"You cannot call a method on a null-valued expression"
Both desktop and server are running PowerShell 4.0 and Internet explorer 11.
I read something a while back that mentioned this may be a bug in 2012 where it doesn't allow this method to click links in IE but cant remember where and if there was a fix!
Does anyone know what causes this and maybe how to resolve it?
another thing i was thinking(if anyone can be bothered to explain!), should i be using invoke-webrequest instead? if so is it possible to log into a site, open some links(doesn't have to be visible on screen) then close confirming it all works?
Thanks in advance for any input!
回答1:
Just enable the Internet Explorer Enterprise Mode.
In Internet Explorer, Press "ALT" key, go to Tools > Enterprise Mode.
If Enterprise Mode is not available: •Launch GPEDIT.MSC •Go to User Configuration > Administrative Templates > Windows Components > Internet Explorer > Let users turn on and use Enterprise Mode from the Tools menu •enabled
and it work !
来源:https://stackoverflow.com/questions/28723314/powershell-internet-explorer-automation-error-server-2012