问题描述
我刚刚开始,所以我一定错过了一些东西。 下载每个文件工作正常:我只是不知道如何附加到同一个输出文件。这是我目前拥有的。
Invoke-WebRequest -Uri "https://website.com/part1.bin" -OutFile "D:\stuff\bigfile.bin"
Invoke-WebRequest -Uri "https://website.com/part2.bin" -OutFile "D:\stuff\bigfile.bin"
Invoke-WebRequest -Uri "https://website.com/part3.bin" -OutFile "D:\stuff\bigfile.bin"
有什么建议吗?谢谢。
解决方法
这是我最终使用的。对我有用!
# Requires Powershell 6.0+ because of AsByteStream
# Example array containing URLs to combine
$arrUrls = @('https://website.com/part1.bin','https://website.com/part2.bin','https://website.com/part3.bin')
$tempFile = "temp.bin"
$outputFile = "wholefile.bin"
# For each url,download in a temp file,then append to output file
foreach ($myUrl in $arrUrls)
{
Invoke-WebRequest -Uri $myUrl -OutFile $tempFile
$byteArray = Get-Content $tempFile -AsByteStream -Raw
Add-Content $outputFile -Value $byteArray -AsByteStream
}