IHTMLDocument2_write Causes Internet Explorer Security Pop Up - Powershell

391 views Asked by At

I have a Powershell script that opens an html file saved locally and parses the file. When it is run from the server where it was created it works fine. However, when I run it from the server where it will need to reside going forward, I keep getting an IE Security pop up. The code is:

$Source = Get-Content -Path $SrcFilePath -raw
$HTML = New-Object -Com "HTMLFile"
$HTML.IHTMLDocument2_write($Source) 
$results = $HTML.all.tags('table') | % OuterHtml

The variable $SrcFilePath is the path to where the HTML file is stored locally. When it gets to the line

$HTML.IHTMLDocument2_write($Source) 

The pop up appears. IE Security Pop up

Once I click "Close", the script resumes. The issue is, this script is going to be automated so no one will physically be around to click the "Close" button when it is appears.

I've tried creating a share to where the html file is saved and adding it to the Trusted sites in IE. I've changed the security level and I've also added about:security_scriptdriver64.exe to Local Intranet in IE, but none of these have worked. Any ideas?

DETAILS UPDATE The server I'm running this on is Windows 2016 and the IE version is 11.

The html file I'm parsing is saved locally on the server i.e. E:\temp\webpage.html

When I created the share and added it to the trusted sites (I tried with both NetBIOS and FQDN), the option "Require server verification" was unchecked.

I've also tried adding about:security_scriptdriver64.exe to Trusted Sites.

I've also turned off "IE Enhanced Security Configuration" through Server Manager for both Admin and Users and this did not work.

UPDATE 2 I had mentioned in my last comment that I had put about:security_scriptdriver64.exe to Trusted Sites, tested, and it did not work. I started looking into using Invoke-WebRequest and playing with that. Was having issues so I thought I would go back to the IHTMLDocument2_write solution. I thought I would use a bare bones html file to start with that I had one table, with one row, and one column. My plan was to slowly start adding tags from the original html file to the barebones. I got as far as updating the title tag when I thought I would try again with the original. It worked.

I removed the about:security_scriptdriver64.exe from Trusted Sites and tried again. It still worked. I left it and everything worked fine so back to the drawing board.

I started again by adding that about line to Trusted Sites. Didn't work so started with the barebones HTML again. There is a block of JavaScript in the file. When I added it, to the barebones file, it didn't work. When I removed it, it worked. So, it's the JavaScript. I still don't understand why it started working last week. The HTML file is always generated with that JavaScript block. SMH.

0

There are 0 answers