Fixes naming of byte data types and functions

This commit is contained in:
Christian Stein 2020-02-04 09:33:27 +01:00
parent 499af2b92e
commit 80975bee24
5 changed files with 90 additions and 90 deletions

View file

@ -42,10 +42,10 @@ For performance metrics you can provide a `Unit` to ensure your graphing is disp
| ms | Milliseconds | The input is indicated as time in milliseconds | | ms | Milliseconds | The input is indicated as time in milliseconds |
| us | Microseconds | The input is indicated as time in microseconds | | us | Microseconds | The input is indicated as time in microseconds |
| B | Bytes | The input is indicated as quantity in bytes | | B | Bytes | The input is indicated as quantity in bytes |
| KB | Kilobytes | The input is indicated as quantity in kilobytes | | KB | Kilobytes | The input is indicated as quantity in Kilobytes |
| MB | Megabytes | The input is indicated as quantity in megabytes | | MB | Megabytes | The input is indicated as quantity in Megabytes |
| GB | Gigabytes | The input is indicated as quantity in gigabytes | | GB | Gigabytes | The input is indicated as quantity in Gigabytes |
| TB | Terabytes | The input is indicated as quantity in terabytes | | TB | Terabytes | The input is indicated as quantity in Terabytes |
| c | Counter | A continues counter increasing values over time | | c | Counter | A continues counter increasing values over time |
## Object Functions ## Object Functions

View file

@ -17,16 +17,16 @@ function Convert-Bytes()
switch ($Unit) { switch ($Unit) {
{ 'B' -contains $_} { $FinalValue = $CurrentValue; $boolOption = $true;} { 'B' -contains $_} { $FinalValue = $CurrentValue; $boolOption = $true;}
{ 'KB' -contains $_} { $FinalValue = ConvertTo-KiloByte $CurrentValue -Unit B; $boolOption = $true;} { 'KB' -contains $_} { $FinalValue = ConvertTo-Kilobyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'MB' -contains $_} { $FinalValue = ConvertTo-MegaByte $CurrentValue -Unit B; $boolOption = $true;} { 'MB' -contains $_} { $FinalValue = ConvertTo-Megabyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;} { 'GB' -contains $_} { $FinalValue = ConvertTo-Gigabyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;} { 'TB' -contains $_} { $FinalValue = ConvertTo-Terabyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'PB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} { 'PB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'KiB' -contains $_} { $FinalValue = ConvertTo-KiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'KiB' -contains $_} { $FinalValue = ConvertTo-Kibibyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'MiB' -contains $_} { $FinalValue = ConvertTo-MiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'MiB' -contains $_} { $FinalValue = ConvertTo-Mebibyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'GiB' -contains $_} { $FinalValue = ConvertTo-GiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'GiB' -contains $_} { $FinalValue = ConvertTo-Gibibyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'TiB' -contains $_} { $FinalValue = ConvertTo-TiBByte $CurrentValue -Unit B; $boolOption = $true;} { 'TiB' -contains $_} { $FinalValue = ConvertTo-Tebibyte $CurrentValue -Unit B; $boolOption = $true;}
{ 'PiB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} { 'PiB' -contains $_} { $FinalValue = ConvertTo-Petabyte $CurrentValue -Unit B; $boolOption = $true;}
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {

View file

@ -7,9 +7,9 @@ function ConvertTo-ByteIEC()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
default { default {
@ -22,7 +22,7 @@ function ConvertTo-ByteIEC()
return $result; return $result;
} }
function ConvertTo-KiBByte() function ConvertTo-Kibibyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -31,9 +31,9 @@ function ConvertTo-KiBByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
default { default {
@ -46,7 +46,7 @@ function ConvertTo-KiBByte()
return $result; return $result;
} }
function ConvertTo-MiBByte() function ConvertTo-Mebibyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -55,9 +55,9 @@ function ConvertTo-MiBByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
default { default {
@ -70,7 +70,7 @@ function ConvertTo-MiBByte()
return $result; return $result;
} }
function ConvertTo-GiBByte() function ConvertTo-Gibibyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -79,9 +79,9 @@ function ConvertTo-GiBByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
default { default {
@ -94,7 +94,7 @@ function ConvertTo-GiBByte()
return $result; return $result;
} }
function ConvertTo-TiBByte() function ConvertTo-Tebibyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -103,9 +103,9 @@ function ConvertTo-TiBByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
default { default {
@ -118,7 +118,7 @@ function ConvertTo-TiBByte()
return $result; return $result;
} }
function ConvertTo-PiBByte() function ConvertTo-Pebibyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -127,9 +127,9 @@ function ConvertTo-PiBByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; }
{ 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } { 'KiB', 'Kibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
{ 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
{ 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } { 'GiB', 'Gibibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
{ 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
{ 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; }
default { default {

View file

@ -23,11 +23,11 @@ function ConvertTo-ByteSI()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
@ -40,21 +40,21 @@ function ConvertTo-ByteSI()
<# <#
.SYNOPSIS .SYNOPSIS
Converts unit sizes to kilobyte. Converts unit sizes to Kilobyte.
.DESCRIPTION .DESCRIPTION
This module converts a given unit size to kilobyte. This module converts a given unit size to Kilobyte.
e.g byte to kilobyte. e.g byte to Kilobyte.
More Information on https://github.com/Icinga/icinga-powershell-framework More Information on https://github.com/Icinga/icinga-powershell-framework
.EXAMPLE .EXAMPLE
PS> ConvertTo-KiloByte -Unit TB 200 PS> ConvertTo-Kilobyte -Unit TB 200
200000000000 200000000000
.LINK .LINK
https://github.com/Icinga/icinga-powershell-framework https://github.com/Icinga/icinga-powershell-framework
.NOTES .NOTES
#> #>
function ConvertTo-KiloByte() function ConvertTo-Kilobyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -63,11 +63,11 @@ function ConvertTo-KiloByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
@ -80,21 +80,21 @@ function ConvertTo-KiloByte()
<# <#
.SYNOPSIS .SYNOPSIS
Converts unit sizes to megabyte. Converts unit sizes to Megabyte.
.DESCRIPTION .DESCRIPTION
This module converts a given unit size to megabyte. This module converts a given unit size to Megabyte.
e.g byte to megabyte. e.g byte to Megabyte.
More Information on https://github.com/Icinga/icinga-powershell-framework More Information on https://github.com/Icinga/icinga-powershell-framework
.EXAMPLE .EXAMPLE
PS> ConvertTo-KiloByte -Unit TB 200 PS> ConvertTo-Kilobyte -Unit TB 200
200000000 200000000
.LINK .LINK
https://github.com/Icinga/icinga-powershell-framework https://github.com/Icinga/icinga-powershell-framework
.NOTES .NOTES
#> #>
function ConvertTo-MegaByte() function ConvertTo-Megabyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -103,11 +103,11 @@ function ConvertTo-MegaByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
@ -120,21 +120,21 @@ function ConvertTo-MegaByte()
<# <#
.SYNOPSIS .SYNOPSIS
Converts unit sizes to gigabyte. Converts unit sizes to Gigabyte.
.DESCRIPTION .DESCRIPTION
This module converts a given unit size to gigabyte. This module converts a given unit size to Gigabyte.
e.g byte to gigabyte. e.g byte to Gigabyte.
More Information on https://github.com/Icinga/icinga-powershell-framework More Information on https://github.com/Icinga/icinga-powershell-framework
.EXAMPLE .EXAMPLE
PS> ConvertTo-GigaByte -Unit TB 200 PS> ConvertTo-Gigabyte -Unit TB 200
200000 200000
.LINK .LINK
https://github.com/Icinga/icinga-powershell-framework https://github.com/Icinga/icinga-powershell-framework
.NOTES .NOTES
#> #>
function ConvertTo-GigaByte() function ConvertTo-Gigabyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -143,11 +143,11 @@ function ConvertTo-GigaByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
@ -160,21 +160,21 @@ function ConvertTo-GigaByte()
<# <#
.SYNOPSIS .SYNOPSIS
Converts unit sizes to terabyte. Converts unit sizes to Terabyte.
.DESCRIPTION .DESCRIPTION
This module converts a given unit size to terabyte. This module converts a given unit size to Terabyte.
e.g byte to terabyte. e.g byte to Terabyte.
More Information on https://github.com/Icinga/icinga-powershell-framework More Information on https://github.com/Icinga/icinga-powershell-framework
.EXAMPLE .EXAMPLE
PS> ConvertTo-TeraByte -Unit GB 2000000 PS> ConvertTo-Terabyte -Unit GB 2000000
2000 2000
.LINK .LINK
https://github.com/Icinga/icinga-powershell-framework https://github.com/Icinga/icinga-powershell-framework
.NOTES .NOTES
#> #>
function ConvertTo-TeraByte() function ConvertTo-Terabyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -183,11 +183,11 @@ function ConvertTo-TeraByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
@ -200,21 +200,21 @@ function ConvertTo-TeraByte()
<# <#
.SYNOPSIS .SYNOPSIS
Converts unit sizes to petabyte. Converts unit sizes to Petabyte.
.DESCRIPTION .DESCRIPTION
This module converts a given unit size to petabyte. This module converts a given unit size to Petabyte.
e.g byte to petabyte. e.g byte to Petabyte.
More Information on https://github.com/Icinga/icinga-powershell-framework More Information on https://github.com/Icinga/icinga-powershell-framework
.EXAMPLE .EXAMPLE
PS> ConvertTo-PetaByte -Unit GB 2000000 PS> ConvertTo-Petabyte -Unit GB 2000000
2 2
.LINK .LINK
https://github.com/Icinga/icinga-powershell-framework https://github.com/Icinga/icinga-powershell-framework
.NOTES .NOTES
#> #>
function ConvertTo-PetaByte() function ConvertTo-Petabyte()
{ {
param( param(
[single]$Value, [single]$Value,
@ -223,11 +223,11 @@ function ConvertTo-PetaByte()
switch ($Unit) { switch ($Unit) {
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; } { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; }
{ 'KB', 'KiloByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; } { 'KB', 'Kilobyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
{ 'MB', 'MegaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; } { 'MB', 'Megabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
{ 'GB', 'GigaByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; } { 'GB', 'Gigabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
{ 'TB', 'TeraByte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; } { 'TB', 'Terabyte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
{ 'PB', 'PetaByte' -contains $_ } { $result = $Value; $boolOption = $true; } { 'PB', 'Petabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
default { default {
if (-Not $boolOption) { if (-Not $boolOption) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;

View file

@ -24,10 +24,10 @@
'us' = 'microseconds'; 'us' = 'microseconds';
'%' = 'percent'; '%' = 'percent';
'B' = 'bytes'; 'B' = 'bytes';
'KB' = 'kilobytes'; 'KB' = 'Kilobytes';
'MB' = 'megabytes'; 'MB' = 'Megabytes';
'GB' = 'gigabytes'; 'GB' = 'Gigabytes';
'TB' = 'terabytes'; 'TB' = 'Terabytes';
'c' = 'counter'; 'c' = 'counter';
}; };