Finding Size of Download

by Jun 7, 2019

When you download files from the internet and use PowerShell, you may want to find out how long the download will take. While you can check the size of the already downloaded binaries, to calculate a progress percentage you also know the size of the total download.

Here is a quick way of finding out the size of a file:

function Get-DownloadSize
{
  [CmdletBinding()]
  param
  (
    [Parameter(Mandatory,ValueFromPipeline)]
    [String]
    $Url
  )
  
  process
  {
    $webRequest = [System.Net.WebRequest]::Create($Url)
    $response = $webRequest.GetResponse()
    $response.ContentLength
    $response.Dispose()
  }
}

And this is an example:

 
PS> "https://github.com/PowerShell/PowerShell/releases/download/v6.2.1/PowerShell-6.2.1-win-x64.zip" | Get-DownloadSize

58716786
 

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where you really still learn something new. But there’s one place you don’t want to miss: PowerShell Conference EU – with 40 renown international speakers including PowerShell team members and MVPs, plus 350 professional and creative PowerShell scripters. Registration is open at www.psconf.eu, and the full 3-track 4-days agenda becomes available soon. Once a year it’s just a smart move to come together, update know-how, learn about security and mitigations, and bring home fresh ideas and authoritative guidance. We’d sure love to see and hear from you!

Twitter This Tip! ReTweet this Tip!