From fdc31beac5fdba692abaf1d69eccbee17073f4de Mon Sep 17 00:00:00 2001 From: Niko Martini Date: Wed, 17 Jul 2019 09:42:35 +0200 Subject: [PATCH] Toolset for conversions --- lib/core/tools/ConvertTo-ByteUnit.psm1 | 190 +++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 lib/core/tools/ConvertTo-ByteUnit.psm1 diff --git a/lib/core/tools/ConvertTo-ByteUnit.psm1 b/lib/core/tools/ConvertTo-ByteUnit.psm1 new file mode 100644 index 0000000..e2db959 --- /dev/null +++ b/lib/core/tools/ConvertTo-ByteUnit.psm1 @@ -0,0 +1,190 @@ +function ConvertTo-Byte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = $Value; + } + KB { + $result = ($Value * [math]::Pow(10, 3)); + } + MB { + $result = ($Value * [math]::Pow(10, 6)); + } + GB { + $result = ($Value * [math]::Pow(10, 9)); + } + TB { + $result = ($Value * [math]::Pow(10, 12)); + } + PB { + $result = ($Value * [math]::Pow(10, 15)); + } + Default {} + } + + return $result; +} +function ConvertTo-KiloByte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = ($Value / 1000); + } + KB { + Write-Output $Value; + } + MB { + $result = ($Value * [math]::Pow(10, 3)); + } + GB { + $result = ($Value * [math]::Pow(10, 6)); + } + TB { + $result = ($Value * [math]::Pow(10, 9)); + } + PB { + $result = ($Value * [math]::Pow(10, 12)); + } + Default {} + } + + return $result; +} + +function ConvertTo-MegaByte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = ($Value / [math]::Pow(10, 6)); + } + KB { + $result = ($Value / [math]::Pow(10, 3)); + } + MB { + $result = $Value; + } + GB { + $result = ($Value * [math]::Pow(10, 3)); + } + TB { + $result = ($Value * [math]::Pow(10, 6)); + } + PB { + $result = ($Value * [math]::Pow(10, 9)); + } + Default {} + } + + return $result; +} + +function ConvertTo-GigaByte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = ($Value / [math]::Pow(10, 9)); + } + KB { + $result = ($Value / [math]::Pow(10, 6)) + } + MB { + $result = ($Value / [math]::Pow(10, 3)); + } + GB { + $result = $Value; + } + TB { + $result = ($Value * [math]::Pow(10, 3)); + } + PB { + $result = ($Value * [math]::Pow(10, 6)); + } + Default {} + } + + return $result; +} + +function ConvertTo-TeraByte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = ($Value / [math]::Pow(10, 12)); + } + KB { + $result = ($Value / [math]::Pow(10, 9)); + } + MB { + $result = ($Value / [math]::Pow(10, 6)); + } + GB { + $result = ($Value / [math]::Pow(10, 3)); + } + TB { + $result = $Value; + } + PB { + $result = ($Value * [math]::Pow(10, 3)); + } + Default {} + } + + return $result; +} + +function ConvertTo-PetaByte() +{ + param( + [single]$Value, + [string]$Unit + ); + + switch ($Unit) { + B { + $result = ($Value / [math]::Pow(10, 15)); + } + KB { + $result = ($Value / [math]::Pow(10, 12)); + } + MB { + $result = ($Value / [math]::Pow(10, 9)); + } + GB { + $result = ($Value / [math]::Pow(10, 6)); + } + TB { + $result = ($Value / [math]::Pow(10, 3)); + } + PB { + $result = $Value; + } + Default {} + } + + return $result; +} \ No newline at end of file