########################################################################################### # Calc-DownloadTime.ps1 - Script to calculate the amount of time it takes to # download on a given connection. # # Usage: Calc-DownloadTime.ps1 [connectionSpeed] # downloadSize - The size of the file to download # connectionSpeed - The speed of the connection. If not supplied, the global # variable $networkSpeed is used # # Script by Captain Literal (aka Mark Sheppard) # http://www.captainliteral.net ########################################################################################### # Script parameters param ([int64]$downloadSize, [int64]$connectionSpeed = $networkSpeed) # Validate arguments $usage = "Usage: calc-downloadTime.ps1 [connectionSpeed]`nIf connectionSpeed is not supplied, global variable `$networkSpeed will be used."; if ($downloadSize -eq $null -or $downloadSize -le 0) { write-host $usage; throw "Please specify a downloadSize"; } if ($connectionSpeed -eq $null -or $connectionSpeed -le 0) { write-host $usage; throw "Please specify a connectionSpeed or set `$networkSpeed variable to use as default"; } # Calculate download time $timeToDownload = New-TimeSpan -seconds $($downloadSize / $connectionSpeed); Write-Host "Your download will take $timeToDownload to complete";