mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-01-28 01:19:21 -05:00
Toolset for conversions
This commit is contained in:
parent
392f0b2a61
commit
fdc31beac5
1 changed files with 190 additions and 0 deletions
190
lib/core/tools/ConvertTo-ByteUnit.psm1
Normal file
190
lib/core/tools/ConvertTo-ByteUnit.psm1
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
function ConvertTo-Byte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = $Value;
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 12));
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 15));
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
function ConvertTo-KiloByte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = ($Value / 1000);
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
Write-Output $Value;
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 12));
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConvertTo-MegaByte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = ($Value / [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = $Value;
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConvertTo-GigaByte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = ($Value / [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 6))
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = $Value;
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConvertTo-TeraByte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = ($Value / [math]::Pow(10, 12));
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = $Value;
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = ($Value * [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConvertTo-PetaByte()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value,
|
||||||
|
[string]$Unit
|
||||||
|
);
|
||||||
|
|
||||||
|
switch ($Unit) {
|
||||||
|
B {
|
||||||
|
$result = ($Value / [math]::Pow(10, 15));
|
||||||
|
}
|
||||||
|
KB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 12));
|
||||||
|
}
|
||||||
|
MB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 9));
|
||||||
|
}
|
||||||
|
GB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 6));
|
||||||
|
}
|
||||||
|
TB {
|
||||||
|
$result = ($Value / [math]::Pow(10, 3));
|
||||||
|
}
|
||||||
|
PB {
|
||||||
|
$result = $Value;
|
||||||
|
}
|
||||||
|
Default {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue