Typically, on a Windows-based PC, you can check an item or a folder’s size by just right-clicking the item or folder and then selecting Properties from the context menu. In this post, we will show you how to check or get Folder Size using PowerShell in Windows 11/10.
A use-case where you may want to use PowerShell instead of the conventional way to get a folder would be if the size of the item or folder is significantly larger — for example, greater than 100 GB. In this case, using the conventional way can take a while for the folder Properties window to finally populate the item’s size — more so, what’s shown might not be the actual size of the folder.
How to get Folder Size using PowerShell in Windows 11/10
For one reason or another, you may need the size of a folder — for example, to estimate the time or duration it will take to move the folder (to another location on the local drive, external drive, or cloud storage) or if considerably a large folder to simply delete it to free up space on your hard drive — you can instantly get the size of a folder/directory using PowerShell. We will discuss this topic under the following subheadings.
- PowerShell commands to get folder size
- Get folder size in Bytes, MBs, and GBs
- Get folder size in decimal
- Get the size of specific file-type items
- Get a folder and sub-folder sizes
- Get folder and sub-folder sizes with a time filter
- Get all subdirectory folder sizes using the PowerShell script
Read: Managing Files and Folders in Windows – Tips & Tricks
1] PowerShell commands to get folder size
The following are the 2 primary PowerShell cmdlets that can be used with switches and parameters to filter the results per your requirement to get the size of a folder.
- Get-ChildItem (Alias: GCI) – This command grabs the information from one or specified directories, including the sub-directories – empty directories are not displayed or shown.
- Measure-Object (Alias: measure) – This command calculates the different properties of a specified directory, including its size.
An alias is an alternative name for the command, so you won’t have to type in the entire command every time.
Read: Analyze Windows Component Store or WinSxS
2] Get folder size in Bytes, MBs, and GBs
The cmdlet will get you the size of the specified folder and the items inside only, and the results will not include the size of the items inside the sub-directories. For example, we will run a command to get the size of the C:\Users\Chidum.Osobalu\Documents\TWC_related folder we have on our PC. Substitute the PathToFolder placeholder with the complete path to the folder/directory for which you want to get the size.
Folder size in Bytes:
Get-ChildItem PathToFolder | Measure-Object -Property Length -sum
Folder size in MBs:
(gci PathToFolder | measure Length -s).sum / 1Mb
Folder size in GBs:
(gci PathToFolder | measure Length -s).sum / 1Gb
The “Sum” field displays the size of the folder in Bytes, MBs, and GBs as the case may be.
Read: How to delete Empty 0-byte files
3] Get folder size in decimal
The output for the folder size in MBs and GBs is ambiguous to understand at a glance due to the size being in many decimal places. So, you can run the command below to round off the result in decimal. Substitute “X” with the number of decimal places you want to round off the result to and specify GB or MB as needed.
"{0:NX} GB" -f ((gci PathToFolder | measure Length -s).sum / 1Gb)
4] Get the size of specific file-type items
If you want to get the size of all the items inside a folder having the same file type/extension, run the command below. Substitute the FileType/Extension placeholder accordingly.
(gci PathToFolder *.FileType/Extension | measure Length -s).sum / 1Gb
Read: How to create multiple folders at once with different names
5] Get folder and sub-folder sizes
To get the folder and sub-folder (including the items inside) sizes, you must use the -Recurse
parameter used in conjecture with the -ErrorAction SilentlyContinue
parameter to bypass directory access errors like Permission is denied, etc.
To get the size of the parent as well as the sub-directories, you can run either of the commands below.
(gci PathToFolder –Recurse -ErrorAction SilentlyContinue| measure Length -s).sum / 1Gb
"{0:NX} GB" -f ((gci –force PathToFolder –Recurse -ErrorAction SilentlyContinue| measure Length -s).sum / 1Gb)
This cmdlet will also include the sizes of any hidden items.
Read: How to create a Folder Tree in Windows
6] Get a folder and sub-folder sizes with a time filter
You can get the size of the parent and the child folders and also apply filters to find the size of the items created on a specific day, a specific month, or a specific year. This you can define by specifying the starting and the ending dates, which are respectively defined by the -gt
(greater than) and -lt
(less than) parameters. The format of the dates is MM/DD/YY.
To get the size of a folder with sub-folders created in a specific period, run the command below. Substitute the MM/DD/YY placeholder accordingly.
(gci -force PathToFolder –Recurse -ErrorAction SilentlyContinue | ? {$_.CreationTime -gt ‘MM/DD/YY’ -AND $_.CreationTime -lt ‘MM/DD/YY’}| measure Length -s).sum / 1Gb
You can also apply these filters using the commands given earlier to get the folder sizes of the parent folders only.
Read: Find File and Folder Ownership information using Command Prompt
7] Get all subdirectory folder sizes using the PowerShell script
Now, to make things more complicated, let’s assume that you must get the size of each sub-directory inside a folder. That can also be accomplished using PowerShell. Of course, To get all subdirectory folder sizes inclusive of the size of the items inside the sub-directories and presented in a neat, tabular format, you can create & run a PowerShell script using the code below.
$targetfolder='DriveLetter:\'
$dataColl = @()
gci -force $targetfolder -ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $_.fullname -ErrorAction SilentlyContinue | % { $len += $_.length }
$foldername = $_.fullname
$foldersize= '{0:N2}' -f ($len / 1Gb)
$dataObject = New-Object PSObject
Add-Member -inputObject $dataObject -memberType NoteProperty -name “foldername” -value $foldername
Add-Member -inputObject $dataObject -memberType NoteProperty -name “foldersizeGb” -value $foldersize
$dataColl += $dataObject
}
$dataColl | Out-GridView -Title “Size of all subdirectories in DriveLetter drive”
Replace the DriveLetter placeholder in the code above accordingly and make sure to turn on PowerShell script execution.
That’s it!
Also read: Useful Commands to Manage Files and Folders via Command Prompt
Is there a way to see the size of a folder in Windows?
The conventional way to check the folder size is to open File Explorer and right-click on the file, folder or drive that you want to see the size. From the menu that appears, select Properties and you will see the total file/drive size. The non-conventional way to perform the same task is to use PowerShell as we have demonstrated in this post above.
Read: How to show Folder size in Windows
What is the DOS command to list folders and sizes?
The dir
command displays information about files and directories, and how much disk space is available. By default, the command displays the name, size, and last modification time of every file in the current directory.