2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Converts unit sizes to byte.
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This module converts a given unit size to byte.
|
|
|
|
|
e.g Kilobyte to Byte.
|
|
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ConvertTo-Byte -Unit TB 200
|
|
|
|
|
200000000000000
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2019-10-30 08:52:37 -04:00
|
|
|
function ConvertTo-ByteSI()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
2019-07-22 10:22:44 -04:00
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
2019-07-17 03:42:35 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 15)); $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-22 10:22:44 -04:00
|
|
|
|
2019-07-17 03:42:35 -04:00
|
|
|
return $result;
|
|
|
|
|
}
|
2019-07-23 03:34:15 -04:00
|
|
|
|
2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2020-02-04 03:33:27 -05:00
|
|
|
Converts unit sizes to Kilobyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
.DESCRIPTION
|
2020-02-04 03:33:27 -05:00
|
|
|
This module converts a given unit size to Kilobyte.
|
|
|
|
|
e.g byte to Kilobyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
2020-02-04 03:33:27 -05:00
|
|
|
PS> ConvertTo-Kilobyte -Unit TB 200
|
2019-10-29 06:34:59 -04:00
|
|
|
200000000000
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2020-02-04 03:33:27 -05:00
|
|
|
function ConvertTo-Kilobyte()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 3)); $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 12)); $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2020-02-04 03:33:27 -05:00
|
|
|
Converts unit sizes to Megabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
.DESCRIPTION
|
2020-02-04 03:33:27 -05:00
|
|
|
This module converts a given unit size to Megabyte.
|
|
|
|
|
e.g byte to Megabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
2020-02-04 03:33:27 -05:00
|
|
|
PS> ConvertTo-Kilobyte -Unit TB 200
|
2019-10-29 06:34:59 -04:00
|
|
|
200000000
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2020-02-04 03:33:27 -05:00
|
|
|
function ConvertTo-Megabyte()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
2019-07-23 03:16:43 -04:00
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 6)); $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 9)); $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2020-02-04 03:33:27 -05:00
|
|
|
Converts unit sizes to Gigabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
.DESCRIPTION
|
2020-02-04 03:33:27 -05:00
|
|
|
This module converts a given unit size to Gigabyte.
|
|
|
|
|
e.g byte to Gigabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
2020-02-04 03:33:27 -05:00
|
|
|
PS> ConvertTo-Gigabyte -Unit TB 200
|
2019-10-29 06:34:59 -04:00
|
|
|
200000
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2020-02-04 03:33:27 -05:00
|
|
|
function ConvertTo-Gigabyte()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
2019-07-23 03:16:43 -04:00
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 9)); $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 6)); $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2020-02-04 03:33:27 -05:00
|
|
|
Converts unit sizes to Terabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
.DESCRIPTION
|
2020-02-04 03:33:27 -05:00
|
|
|
This module converts a given unit size to Terabyte.
|
|
|
|
|
e.g byte to Terabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
2020-02-04 03:33:27 -05:00
|
|
|
PS> ConvertTo-Terabyte -Unit GB 2000000
|
2019-10-29 06:34:59 -04:00
|
|
|
2000
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2020-02-04 03:33:27 -05:00
|
|
|
function ConvertTo-Terabyte()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
2019-07-23 03:16:43 -04:00
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 12)); $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = ($Value * [math]::Pow(10, 3)); $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 06:34:59 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2020-02-04 03:33:27 -05:00
|
|
|
Converts unit sizes to Petabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
.DESCRIPTION
|
2020-02-04 03:33:27 -05:00
|
|
|
This module converts a given unit size to Petabyte.
|
|
|
|
|
e.g byte to Petabyte.
|
2019-10-29 06:34:59 -04:00
|
|
|
|
2019-10-31 12:24:30 -04:00
|
|
|
More Information on https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.EXAMPLE
|
2020-02-04 03:33:27 -05:00
|
|
|
PS> ConvertTo-Petabyte -Unit GB 2000000
|
2019-10-29 06:34:59 -04:00
|
|
|
2
|
|
|
|
|
.LINK
|
2019-10-31 12:24:30 -04:00
|
|
|
https://github.com/Icinga/icinga-powershell-framework
|
2019-10-29 06:34:59 -04:00
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2020-02-04 03:33:27 -05:00
|
|
|
function ConvertTo-Petabyte()
|
2019-07-17 03:42:35 -04:00
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[single]$Value,
|
|
|
|
|
[string]$Unit
|
|
|
|
|
);
|
|
|
|
|
|
2019-07-23 03:16:43 -04:00
|
|
|
switch ($Unit) {
|
2019-07-22 10:22:44 -04:00
|
|
|
{ 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(10, 15)); $boolOption = $true; }
|
2020-02-04 03:33:27 -05:00
|
|
|
{ '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; }
|
|
|
|
|
{ 'PB', 'Petabyte' -contains $_ } { $result = $Value; $boolOption = $true; }
|
2019-07-22 10:22:44 -04:00
|
|
|
default {
|
2019-07-23 03:34:15 -04:00
|
|
|
if (-Not $boolOption) {
|
2020-02-03 11:56:34 -05:00
|
|
|
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|
2019-07-17 03:42:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
2019-07-23 03:34:15 -04:00
|
|
|
}
|