function ConvertTo-Byte() { param( [single]$Value, [string]$Unit ); switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; } function ConvertTo-KiloByte() { param( [single]$Value, [string]$Unit ); switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; } function ConvertTo-MegaByte() { param( [single]$Value, [string]$Unit ); switch($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; } function ConvertTo-GigaByte() { param( [single]$Value, [string]$Unit ); switch($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; } function ConvertTo-TeraByte() { param( [single]$Value, [string]$Unit ); switch($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; } function ConvertTo-PetaByte() { param( [single]$Value, [string]$Unit ); switch($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; } { 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } { 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'PT', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { Throw 'Invalid input'; } } } return $result; }