mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
144 lines
No EOL
5.3 KiB
PowerShell
144 lines
No EOL
5.3 KiB
PowerShell
#
|
|
|
|
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;
|
|
} |