2

Ok, I am trying to download a file off of a web link that we use with powershell. I am downloading a zip file where the begining of the name is always the same, but the the middle part will change based off of the version number of the zip. I have been able to get the file to download when I use the fully qualified web address and have the file name hard coded into the script. I have tried every version of using the wild cards to get all the most common version of the zip, but it errors out saying that it can't find the file on there server. This is the code that I have already, and any help would be greatly appreciated since I feel like I am at a wall with it.

$url = 'http://blah/blah/blah/My File Name 11.1111.11.zip'
$localFileName = 'C:\temp\MYzip.zip'

Invoke-WebRequest $url -UseDefaultCredentials -OutFile $localFileName
4

1 回答 1

4

如果该站点启用了目录浏览(除非您可以控制该站点并且可以打开它),否则您可以执行以下操作:

$url = 'http://blah/blah/blah/'
$wr = iwr $url
$filename = $wr.Links.href | Where {$_ -match 'My File Name.*?\.zip'}
$wr = iwr "$url/$filename"

如果该站点没有启用目录浏览,那么它肯定有一个页面,其中包含指向 ZIP 文件的链接。下载该页面并使用相同的$wr.Links.href技巧获取所有链接并查找与“我的文件名。*?.zip”匹配的链接。

于 2013-11-14T04:33:20.360 回答