forked from jacksonbrumbaugh/JklPoshToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-PrettySize.ps1
49 lines (43 loc) · 1.14 KB
/
Get-PrettySize.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function Get-PrettySize {
param(
[long[]]
[Parameter(
Mandatory,
ValueFromPipeline)]
[Alias('Length')]
$Size
)
process {
foreach ($S in $Size) {
$PrettySize = Switch ($S) {
{ $_ / 1TB -gt 0.95 } {
$Unit = "TB"
$_ / 1TB
break
}
{ $_ / 1GB -gt 0.95 } {
$Unit = "GB"
$_ / 1GB
break
}
{ $_ / 1MB -gt 0.95 } {
$Unit = "MB"
$_ / 1MB
break
}
{ $_ / 1KB -gt 0.95 } {
$Unit = "KB"
$_ / 1KB
break
}
Default {
$Unit = "B"
$_
break
}
}
$PrettySize = (("{0:N1}" -f $PrettySize) -replace "^0.0$",'0') + " $Unit"
$PrettySize
} # End foreach Size
} # End process block
} # End function