mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge branch 'nmartini/module_rewrite' into testing
This commit is contained in:
commit
489e2862ca
1 changed files with 144 additions and 0 deletions
144
lib/core/tools/ConvertTo-ByteUnit.psm1
Normal file
144
lib/core/tools/ConvertTo-ByteUnit.psm1
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
#
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in a new issue