How to get the folder size using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

We will first retrieve the content of the folder using the Get-ChildItem command and then pipeline the Measure-Object command as shown below.

Get-ChildItem C:\Temp\ -Recurse | Measure-Object -Property Length -Sum


Count : 1514
Average :
Sum : 372060503
Maximum :
Minimum :
Property : Length

So the above output shows that there is a total of 1514 files and folders and the sum shows the size of all the files and folders combined in KB. We can convert it to the MB as shown below.

(Get-ChildItem C:\Temp\ -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB

We can get the round figure,

   ((Get-ChildItem C:\Temp\ -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB),2

You can check the same on the folder path.

Published on 30-Mar-2021 17:01:19