$dd = Get-Date -Format dd
$mn = Get-Date -Format MMM
$yr = Get-Date -Format yyyy
$umn = $mn.ToUpper()
$dt = $dd + $umn + $yr
$Zfile = 'cm'+$dt+'data.csv.zip'
$Tfile='DATA'+$dt+'.CSV'
$URL = 'https://archives.XYZ.com/content/historical/XYZ/'+$yr+'/'+$umn+'/'+$Zfile
Invoke-WebRequest -URI $URL -OutFile D:\MYDATA\$Zfile
#$URL
I have this script and if I print $URL then I can see https but when run script in error message I can only http and that's why facing "Access Denied"
Invoke-WebRequest : Access Denied
You don't have permission to access "http://archives.XYZ.com/content/historical/XYZ/2021/JULY/MYFILE.csv.zip" on this server.
Reference #18.b5fdd417.1627307177.3a23ec35
At D:\mywork\XYZ.ps1:12 char:1
Invoke-WebRequest -URI $URL -OutFile D:\MYDATA\$Zfi ...
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand