PowerShell File Transfer Calculator

# Function to convert data size to megabits
function Convert-DataSizeToMb {
    param (
        [float]$dataSize,
        [string]$unit
    )
    switch ($unit.ToLower()) {
        "kb" { return $dataSize * 0.008 }
        "mb" { return $dataSize * 8 }
        "gb" { return $dataSize * 8192 }
        "tb" { return $dataSize * 8388608 }
        default { throw "Invalid data size unit" }
    }
}
 
# Function to convert transfer rate to megabits per second
function Convert-TransferRateToMbps {
    param (
        [float]$transferRate,
        [string]$unit
    )
    switch ($unit.ToLower()) {
        "kbps" { return $transferRate * 0.001 }
        "mbps" { return $transferRate }
        "gbps" { return $transferRate * 1000 }
        default { throw "Invalid transfer rate unit" }
    }
}
 
# Prompt for the amount of data and its unit
$dataAmount = Read-Host "Enter the amount of data to transfer"
$dataUnit = Read-Host "Enter the unit of data size (KB, MB, GB, TB)"
 
# Prompt for the transfer rate and its unit
$transferRate = Read-Host "Enter the transfer rate"
$rateUnit = Read-Host "Enter the unit of transfer rate (kbps, mbps, gbps)"
 
# Convert data size and transfer rate to megabits
$dataAmountMb = Convert-DataSizeToMb -dataSize $dataAmount -unit $dataUnit
$transferRateMbps = Convert-TransferRateToMbps -transferRate $transferRate -unit $rateUnit
 
# Calculate transfer time in seconds
$transferTimeSeconds = $dataAmountMb / $transferRateMbps
 
# Convert transfer time to hours, minutes, and seconds
$transferTimeHours = [math]::Floor($transferTimeSeconds / 3600)
$transferTimeMinutes = [math]::Floor(($transferTimeSeconds % 3600) / 60)
$transferTimeSeconds = [math]::Floor($transferTimeSeconds % 60)
 
# Output the transfer time
Write-Output "Transfer time: $transferTimeHours hours, $transferTimeMinutes minutes, $transferTimeSeconds seconds"

Leave a Reply

Your email address will not be published. Required fields are marked *