Reputation: 171
I'm trying to retrieve a file from an external HTTPS site. My code below works a treat in POSH 3.0, but in POSH 4.0, not so much. The message I get is below. Anyone experiencing the same issue, know how to resolve this or a workaround?
Invoke-WebRequest :
Authentication Required.
You must be authenticated to access this URL.
URL: https://www.mywebsite.com
User name:
At line:4 char:1
+ Invoke-WebRequest -Uri https://www.mywebsite.com/report.pdf ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
$pw = ConvertTo-Securestring -AsPlainText -Force -String "myPWD"
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ("myUser",$pw)
Invoke-WebRequest -Uri https://www.mywebsite.com/report.pdf -Credential $cred -OutFile C:\report.pdf
Upvotes: 1
Views: 8947
Reputation: 171
So I found that even though I could access the website and retrieve my content with my browser, the McAfee Web Gateway was preventing Powershell from doing the same thing. Once we whitelisted the URL, BOOM, no problems. Thanks everyone for the additional ideas in helping me troubleshoot this!
Upvotes: 1