首页 > 解决方案 > Invoke-WebRequest 中的 URL 未按预期工作

问题描述

$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

我有这个脚本,如果我打印 $URL 然后我可以看到 https 但是当在错误消息中运行脚本时我只能 http 这就是为什么面临“拒绝访问”

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

标签: powershellinvoke-webrequest

解决方案


推荐阅读