VM上使用Powershell不稳定文件下载

VM上使用Powershell不稳定文件下载

本文介绍了在Azure VM上使用Powershell不稳定文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Invoke-WebRequest命令下载文件时,我注意到Azure虚拟机上有一些奇怪的行为.好像下载流超级断断续续.通常,Azure VM超级快地下载文件,所以不确定是什么原因造成的.该文件位于与VM相同区域的Azure Blob存储中.当我通过网络浏览器下载文件时,仅需3秒钟.使用Powershell大约需要一分钟!

这是使用powershell完成后的网络屏幕截图.

为了澄清,这是我用来下载文件的代码...

$dest = "$($buildDir)\MyStuff.zip"
Invoke-WebRequest "https://mystorage.blob.core.windows.net/apps/$($using:buildNumber)/App/MyStuff.zip" -OutFile $dest

我正在使用azure画廊中2016-Datacenter映像上随附的任何版本的Powershell.

解决方案

是的,PowerShell cmdlet Invoke-WebRequest下载文件的速度比Web浏览器慢,因为进度报告每个字节的开销都比其他(Web浏览器)高./p>

有关Invoke-WebRequest速度的详细信息,请参阅@jasongin的答案.

如果您想通过PowerShell下载文件,也许我们可以使用 WebClient类,它将比 WebRequest类,我们可以使用如下命令:

$download = New-Object net.webclient
$download.Downloadfile($source_url, $local_url)

希望这会有所帮助.

I'm noticing some strange behavior on an Azure Virtual Machine when downloading a file using the Invoke-WebRequest command. Seems like the download stream is super choppy. Normally, Azure VMs download files super fast, so not sure what's causing this. The file lives in azure blob storage in the same region as the VM. When I download the file via web browser, it only takes 3 seconds. Using powershell takes about a minute!

Here is a screen capture of the network when done using powershell.

To clarify, this is the code I'm using to download a file...

$dest = "$($buildDir)\MyStuff.zip"
Invoke-WebRequest "https://mystorage.blob.core.windows.net/apps/$($using:buildNumber)/App/MyStuff.zip" -OutFile $dest

I'm using whatever version of powershell comes on the 2016-Datacenter image in the azure gallery.

解决方案

Yes, PowerShell cmdlet Invoke-WebRequest download files slow than web browser, because the progress reporting every byte, the overhead is high than others(web browser).

More information about speed of Invoke-WebRequest, please refer to the answer of @jasongin.

If you want to download file via PowerShell, maybe we can use WebClient Class, that will fast than WebRequest Class, we can use command like this:

$download = New-Object net.webclient
$download.Downloadfile($source_url, $local_url)

Hope this helps.

这篇关于在Azure VM上使用Powershell不稳定文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:37