mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-23 16:19:37 -05:00
Add first draft unit determination tools
This commit is contained in:
parent
58d2aa7403
commit
e07f7f1482
2 changed files with 41 additions and 0 deletions
21
lib/core/tools/Get-UnitPrefixIEC.psm1
Normal file
21
lib/core/tools/Get-UnitPrefixIEC.psm1
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
function Get-UnitPrefixIEC()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value
|
||||||
|
);
|
||||||
|
|
||||||
|
If ( $Value / [math]::Pow(2, 50) -ge 1 ) {
|
||||||
|
return 'PiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 40) -ge 1 ) {
|
||||||
|
return 'TiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 30) -ge 1 ) {
|
||||||
|
return 'GiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 20) -ge 1 ) {
|
||||||
|
return 'MiB'
|
||||||
|
} elseif ( $Value / [math]::Pow(2, 10) -ge 1 ) {
|
||||||
|
return 'KiB'
|
||||||
|
} else {
|
||||||
|
return 'B'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
20
lib/core/tools/Get-UnitPrefixSI.psm1
Normal file
20
lib/core/tools/Get-UnitPrefixSI.psm1
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
function Get-UnitPrefixSI()
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
[single]$Value
|
||||||
|
);
|
||||||
|
|
||||||
|
If ( $Value / [math]::Pow(10, 15) -ge 1 ) {
|
||||||
|
return 'PB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 12) -ge 1 ) {
|
||||||
|
return 'TB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 9) -ge 1 ) {
|
||||||
|
return 'GB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 6) -ge 1 ) {
|
||||||
|
return 'MB'
|
||||||
|
} elseif ( $Value / [math]::Pow(10, 3) -ge 1 ) {
|
||||||
|
return 'KB'
|
||||||
|
} else {
|
||||||
|
return 'B'
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue