sudheer kumar
sudheer kumar

Reputation: 65

powershell script to get both size and size on disk of directory

I was writing a power shell script to get a size of directory

(get-childitem <path> -recurse | measure-object -property length -sum).sum/1MB

now I want both "size" and "size on the disk" of a folder to be displayed as output

Upvotes: 3

Views: 7124

Answers (1)

Harsh Jaswal
Harsh Jaswal

Reputation: 447

Try this:

GCI <Path> -Recurse |
Group-Object -Property Directory | % {
  New-Object psobject -Property @{
    Name = $_.Name
    Size = ($_.Group | ? {!($_.PSIsContainer)} | Measure-Object Length -Sum).Sum
  }
} |
Sort-Object -Property Size -Descending

Upvotes: 3

Related Questions