使用powershell从URL下载多个文件

使用powershell从URL下载多个文件,powershell,scripting,Powershell,Scripting,我有一个由100个URL组成的文本文件。这些URL再次包含不同的安装程序文件(.exe、.msi、.bat、.txt等) 我需要使用Invoke WebRequest将这些文件下载到本地计算机上。但是,如果不在输出路径中指定文件的扩展名类型,如何下载文件 File.txt: https://foo.com/path/to/file.exe?token=ahcdj009a https://foo.com/path/to/file.msi?token=ansjndhkg https://foo.co

我有一个由100个URL组成的文本文件。这些URL再次包含不同的安装程序文件(.exe、.msi、.bat、.txt等)

我需要使用Invoke WebRequest将这些文件下载到本地计算机上。但是,如果不在输出路径中指定文件的扩展名类型,如何下载文件

File.txt:

https://foo.com/path/to/file.exe?token=ahcdj009a
https://foo.com/path/to/file.msi?token=ansjndhkg
https://foo.com/path/to/file.lpr?token=553dndgbs
https://foo.com/path/to/file.txt?token=amnewa453
...etc        

如何使用Invoke WebRequest PowerShell命令将URL中的所有文件下载到Windows本地计算机上?

如果模式保持这种状态(.+文件扩展名+?),则可以使用这两行,而$fileExt是文件扩展名。希望能有点帮助:)


你不会只想使用iwr。除此之外,您还需要使用其他工具来下载文件。启动BitsTranfer应该可以工作

例如,如果要下载所有链接图像,可以尝试以下方法:

$URL = "http://www.website.com"

$Site = iwr -Uri $URL

$Images = ($Site).Images.src

foreach ($Image in $Images) {

Start-BitsTransfer -Source $Image -Destination C:\Test\ -TransferType Download

}
和的可能副本
$URL = "http://www.website.com"

$Site = iwr -Uri $URL

$Images = ($Site).Images.src

foreach ($Image in $Images) {

Start-BitsTransfer -Source $Image -Destination C:\Test\ -TransferType Download

}