icinga-powershell-framework/lib/core/tools/ConvertTo-ByteUnit.psm1

226 lines
4.7 KiB
PowerShell
Raw Normal View History

2019-07-17 03:42:35 -04:00
function ConvertTo-Byte()
{
param(
2019-07-17 10:37:38 -04:00
[single]$Value,
[string]$Unit #Validation PT PetaByte
2019-07-17 03:42:35 -04:00
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
$result = $Value;
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 12));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 15));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}
function ConvertTo-KiloByte()
{
param(
[single]$Value,
[string]$Unit
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
$result = ($Value / 1000);
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
$result = $Value;
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 12));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}
function ConvertTo-MegaByte()
{
param(
[single]$Value,
[string]$Unit
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
$result = ($Value / [math]::Pow(10, 6));
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = $Value;
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}
function ConvertTo-GigaByte()
{
param(
[single]$Value,
[string]$Unit
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
$result = ($Value / [math]::Pow(10, 6));
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = $Value;
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}
function ConvertTo-TeraByte()
{
param(
[single]$Value,
[string]$Unit
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 12));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = $Value;
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value * [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}
function ConvertTo-PetaByte()
{
param(
[single]$Value,
[string]$Unit
);
switch ($Unit) {
2019-07-17 10:37:38 -04:00
Byte {
$result = ($Value / [math]::Pow(10, 15));
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
KiloByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 12));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
MegaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 9));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
GigaByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 6));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
TeraByte {
2019-07-17 03:42:35 -04:00
$result = ($Value / [math]::Pow(10, 3));
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
2019-07-17 10:37:38 -04:00
PetaByte {
2019-07-17 03:42:35 -04:00
$result = $Value;
2019-07-17 10:37:38 -04:00
break;
2019-07-17 03:42:35 -04:00
}
Default {}
}
return $result;
}