This PowerShell function will calculate how long it will take to transfer a given number of bytes at a given speed (in bits per second). Optionally, you can specify transfer overhead, which defaults to ten percent.
Example Usage
PS C:\> Get-TransferTime -FileSize 4.4gb -Speed 2mb Days : 0 Hours : 5 Minutes : 0 Seconds : 22 TotalDays : 0.208587962962963 TotalHours : 5.00611111111111 TotalMinutes : 300.366666666667 TotalSeconds : 18022
The Function
<#
.Synopsis
Data transfer time calculation.
.DESCRIPTION
Calculate how long it would take to transfer a given number of bytes at a given speed.
.PARAMETER FileSize
File Size in bytes. Can specify with GB, MB, etc.
.PARAMETER Speed
Transfer speed in bits. Can specify with GB, MB, etc.
.PARAMETER OverheadPercent
Transfer overhead percent. Defaults to 10.
.EXAMPLE
Get-TransferTime -FileSize 4.4gb -Speed 2mb
.EXAMPLE
Get-TransferTime -FileSize 50mb -Speed 10mb -OverheadPercent 6
.NOTES
Ken Bradley, 2015-12-10
#>
function Get-TransferTime
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[double]$FileSize, # bytes, can specify GB, MB, etc
#Speed help!
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[double]$Speed, # bits, can specify GB, MB, etc
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=2)]
[double]$OverheadPercent=10
)
# Scale percent so 100% = 1.0
$ScaledPercent = 1 + ($OverheadPercent / 100)
# Calculate seconds
$Result = ($FileSize * 8 * $ScaledPercent) / $Speed
# Output the result nicely formated
New-TimeSpan -Seconds $Result | Format-List -Property Days, Hours, Minutes, Seconds, TotalDays, TotalHours, TotalMinutes, TotalSeconds
}
[EDIT: Previously, there was an error with OverheadPercent being excluded from the calculation. It has been added back. Thanks to JG for catching this.]