1
votes

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 
1
And yes, the credentials are correct. I can access the site from my browser. :)cluckinchicken
if you run with -Debug do you get any extra clues?RickH
Exact same results unfortunately.cluckinchicken
This posts suggests the behavior should be the same in V3 or V4. Does anyone get similar results? stackoverflow.com/questions/21554993/…cluckinchicken
Go download Fiddler and examine the RAW Request between using v3 and v4 and see if you can spot any differences.Keith Hill

1 Answers

1
votes

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!