2019-10-30 08:52:37 -04:00
|
|
|
function ConvertTo-ByteIEC()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConvertTo-KibiByte()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConvertTo-MibiByte()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConvertTo-GibiByte()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConvertTo-TibiByte()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ConvertTo-PitiByte()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
|
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; }
|
|
|
|
|
{ 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; }
|
|
|
|
|
{ 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; }
|
|
|
|
|
{ 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; }
|
|
|
|
|
{ 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; }
|
|
|
|
|
{ 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
|
|
|
|
default {
|
|
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-10-30 08:52:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|