获取下载文件的大小

在使用PowerShell下载文件时,总希望展示一个进度条来查看下载进程

这就需要知道下载文件的大小,然后通过百分比的形式显示进度

  要获得下载文件的大小可以使用如下:

function Get-DownloadSize
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory,ValueFromPipeline)]
        [String]
        $url
    )

    Process
    {
        $webRequest=[System.Net.WebRequest]::Create($url)
        $response=$webRequest.GetResponse()
        $response.ContentLength
        #($response.ContentLength/1024kb).ToString()+' mb'
    }
}

效果如下:

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/11107413.html