How to Get the Size of the Folder Including the Subfolders in PowerShell

How to Get the Size of the Folder Including the Subfolders in PowerShell

This tutorial demonstrates how to get folder size, including subfolders using PowerShell.

Get the Size of the Folder, Including the Subfolders in PowerShell

To get the size of a folder, we need to run a few commands together. First, we need to get the children of the given folder, measure the length property for the folder, and finally, show the Sum object.

See the steps below:

The command to get the children of the given folder is:

Get-ChildItem "C:\Users"

The above command will show the children of the given folder. Here, the children mean the subfolders and other items:

    Directory: C:\Users


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         1/31/2022   1:24 PM                DefaultAppPool
d-r---         4/26/2021   3:32 PM                Public
d-----         11/1/2022   1:33 PM                Sheeraz
-a----         7/14/2022   2:33 PM            224 Example.java

As we can see, the folder has three subfolders and one file. Now, to get all the items of subfolders, we need to run the following command:

Get-ChildItem -Path "C:\Users" -Recurse -ErrorAction SilentlyContinue |

Then to measure the size of all subfolders and items, we need to run the following command:

Measure-Object -Property Length -Sum |

Finally, after measuring the length property for all the content of the folder, now show the object:

Select-Object Sum

The sum object will show the size of the folder, including subfolders. And to show the number of items in the folder, we use the Count object:

Select-Object Count

The above command will show the size of folder Sheeraz in MBS. See the output:

36304.1059274673 MB
Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook

Related Article - PowerShell Folder