Invoke-WebRequest causes IE content blocked dialog
Asked Answered
O

5

15

On a Windows server with Internet Explorer Enhanced Security Configuration enabled, calling Invoke-WebRequest like this:

Invoke-WebRequest "http://localhost" -UseBasicParsing -UseDefaultCredentials

Results in this error dialog:

Internet Explorer dialog - Content within this application coming from the website listed below is being blocked by Internet Explorer Enhanced Security Configuration

Considering that this script is intended to be run remotely, I'd like to avoid the dialog appearing at all.

Obstacle answered 16/9, 2014 at 7:27 Comment(0)
C
7

Click Add and add about:security_powershell.exe to Trusted Sites.

Cribble answered 16/9, 2014 at 10:25 Comment(6)
A good suggestion - I tried that. I then get subsequent errors relating to other files that the initial page references. Looks like Invoke-WebRequest is behaving like a regular browser, rather than just retrieving the initial request's contentObstacle
That's exactly what Invoke-WebRequest does. You can use System.Net.WebClient as an alternative but there will be no client-side processing there(no ajax).Cribble
Exactly what I ended up using :-)Obstacle
In my case adding about:/assets/default.js to Trusted Sites was also required.Craquelure
but this defeats automation. The OP stated he is trying to execute remotely.Gesticulation
This is not a solution for script automation as it involves UI!Wendellwendi
R
24

It seems Invoke-WebRequest requires IE unless you specify -UseBasicParsing parameter. see: https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.utility/Invoke-WebRequest

-UseBasicParsing Indicates that the cmdlet uses the response object for HTML content without Document Object Model (DOM) parsing.

This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.

Resoluble answered 5/2, 2017 at 12:18 Comment(3)
Wouldn't it be the opposite? If "this parameter is required when IE is not installed...".Slavish
This didn't work for me. Adding -UseBasicParsing still resulted in the IE ESC pop-up for new URLs; at least at PowerShell 3.0.Uriiah
I saw this in the documentation: This parameter has been deprecated. Beginning with PowerShell 6.0.0, all Web requests use basic parsing only. This parameter is included for backwards compatibility only and any use of it has no effect on the operation of the cmdlet.Presumptuous
C
7

Click Add and add about:security_powershell.exe to Trusted Sites.

Cribble answered 16/9, 2014 at 10:25 Comment(6)
A good suggestion - I tried that. I then get subsequent errors relating to other files that the initial page references. Looks like Invoke-WebRequest is behaving like a regular browser, rather than just retrieving the initial request's contentObstacle
That's exactly what Invoke-WebRequest does. You can use System.Net.WebClient as an alternative but there will be no client-side processing there(no ajax).Cribble
Exactly what I ended up using :-)Obstacle
In my case adding about:/assets/default.js to Trusted Sites was also required.Craquelure
but this defeats automation. The OP stated he is trying to execute remotely.Gesticulation
This is not a solution for script automation as it involves UI!Wendellwendi
A
1

Perhaps systems have changed since Raf's answer above was posted. I found it didn't work for me.

What did work was:-

  1. Open Internet Explorer
  2. Go to Tools->Internet options
  3. Select the Security Tab
  4. Click Local Intranet
  5. Click sites
  6. Enter *.security_powershell.exe
  7. Click Add
Arapaima answered 23/6, 2016 at 7:44 Comment(3)
I didn't have the "Add..." button shown in the OP's screenshot but otherwise the same error message, and this worked for me as well (though I added a different page to Trusted Sites instead of Local Intranet).Stets
OP is showing he is looking for a PowerShell based solution and it must be able to execute remotely. Why would you suggest a GUI solution? This defeats automation.Gesticulation
@Steven my understanding of the question is that they're attempting to run a powershell script on the client not the server. If you don't want to use a GUI on the client to make these changes to the security policy you can use Windows Server Group Policy to apply security changes to all the machines within a domainArapaima
B
0

Just return a single property of the object that comes back from the call, ie:

(invoke-webrequest -Uri https://www.google.com).RawContent

(invoke-webrequest -Uri https://www.google.com).StatusDescription

I don't really know what the default call for invoke-webrequest is doing, but it must be doing a lot more than just getting a raw HTTP response.

Brooking answered 8/6, 2021 at 18:59 Comment(0)
A
0

I know I am posting on very old post.

I am also getting this issue "Invoke-WebRequest causes IE content blocked dialog" and option "Click Add and add about:security_powershell.exe to Trusted Sites." isn't working for me because I am hitting web-site in loop by passing parameter. so every time there will be new URL, like below. Any idea to permanently unblock and suppress this dialog box.

 #$URL='https://www.mywebsite.com/page/Public.aspx?id='+$CODE+'&qtr=8&Qtr=December'
Aegean answered 16/10, 2021 at 15:55 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewObmutescence

© 2022 - 2024 — McMap. All rights reserved.