-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathGet-DirSize.ps1
More file actions
34 lines (30 loc) · 729 Bytes
/
Get-DirSize.ps1
File metadata and controls
34 lines (30 loc) · 729 Bytes
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
<#
.SYNOPSIS
Report the size of all items in the specified folder.
#>
param (
$dir,
[System.Management.Automation.SwitchParameter] $la)
$bytes = 0
$count = 0
Get-Childitem $dir -force:$la | Foreach-Object `
{
if ($_ -is [IO.FileInfo]) {
$bytes += $_.Length
$count++
}
}
Write-Host "`n " -NoNewline
if ($bytes -ge 1KB -and $bytes -lt 1MB) {
Write-Host("" + [Math]::Round(($bytes / 1KB), 2) + " KB") -NoNewLine
}
elseif ($bytes -ge 1MB -and $bytes -lt 1GB) {
Write-Host("" + [Math]::Round(($bytes / 1MB), 2) + " MB") -NoNewLine
}
elseif ($bytes -ge 1GB) {
Write-Host("" + [Math]::Round(($bytes / 1GB), 2) + " GB") -NoNewLine
}
else {
Write-Host("" + $bytes + " bytes") -NoNewLine
}
Write-Host " in $count files"