我有一个几乎可以运行的脚本,但是我需要在URL上添加解析或通配符,因为URL会变成每个月都不知道的字符。我必须使用New-Object System.Net.WebClient,因为调用Web请求被阻止。因此,我在考虑是否有人知道如何使用我会知道的字符下载链接并删除其余的链接。
下面的链接示例
Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip
Full-CSV-data-file-Dec18-ZIP-3427K.zip
Full-CSV-data-file-Nov18-ZIP-3543K-21860.zip
所以在上面的链接上,我知道最新文件将包含Jan19,这是一个zip文件。我正在使用的脚本是
$currentMonthNo = get-date -format "MM"
$currentMonthName = (get-date((get-date).addmonths(-2)) -format MMM)
$currentYearNo = get-date –format yy
$url = "http://www.website.com/Full-CSV-data-file-$currentMonthName$currentYearNo-ZIP-3633K-53821.zip"
$output = "C:\Folder\Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
#OR
(New-Object System.Net.WebClient).DownloadFile($url, $output)
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Write-Output $url
Start-Sleep -s 6