How to Utilize PowerShell to Calculate Folder Size on Windows

How to Utilize PowerShell to Calculate Folder Size on Windows
- Advertisement -

If you’re wondering which folders are using a lot of storage on your Windows computer, finding out their sizes can be really useful. This helps you spot the big storage eaters and can be handy if you want to transfer a large folder to a USB drive or cloud storage. While the familiar File Explorer can do this, it might take a while for really big folders, and it’s not the best choice if you’re managing lots of computers in a business or organization. So, let’s explore using PowerShell to quickly figure out folder sizes on Windows.

- Advertisement -

Contents

How to Find a Folder’s Size Using PowerShell on Windows:

PowerShell offers a solution with its Get-ChildItem and Measure-Object cmdlets, making folder size calculation straightforward. We’ll use the Length property and Sum parameter to get the results you need.

  • Press the Windows key and type “powershell.”
  • Right-click on “Windows PowerShell” and choose “Run as administrator.” Confirm with a “Yes” to bypass User Account Control.
  • In the PowerShell window, enter this command:
Get-ChildItem FolderPath | Measure-Object -Property Length -sum
  • Replace “FolderPath” with the directory path containing your target folder.
  • The result will show the number of items in the folder and its size in bytes. To convert it to KBs or MBs, divide by 1024 or 1024 twice, respectively. For gigabytes, divide by a million.

READ ALSO: 10 Windows Command Prompt (CMD) Commands You Must Know

How to Find Subfolder Sizes Using PowerShell:

If you want to determine the total size of files in a folder and its subfolders, add the -Recurse parameter to the command:

((gci -force c:\Users -Recurse -ErrorAction SilentlyContinue | measure Length -s).sum / 1Gb)

This command calculates the size of the “c:\Users” directory, including subdirectories and hidden files. The -ErrorAction SilentlyContinue parameter helps suppress potential error messages during the process.

How to Get Subfolder Sizes in a Table Format Using PowerShell:

For a more detailed view of subfolders and their sizes, consider using a PowerShell script. It’s especially useful for extensive directories. Here’s how:

Open PowerShell ISE by searching for it.

Copy and paste the provided script into the PowerShell ISE console, adjusting the “targetfolder” variable to your preferred directory.

Run the script (F5), and you’ll see a graphical “Size Of Subdirectories” dialog listing all subdirectories and their sizes.

Furthermore, PowerShell offers comparison operators to filter results based on specific criteria, such as file creation dates. For example, to get file sizes for folders created within a particular date range:

(gci -force E:\Download –Recurse -ErrorAction SilentlyContinue | ? {$_.CreationTime -gt '01/23/23' -AND $_.CreationTime -lt '02/23/23'}| measure Length -s).sum / 1Gb

Feel free to customize and experiment with these PowerShell commands to suit your specific needs and efficiently manage your folders and files.

Conclusion

In summary, PowerShell provides a robust method for calculating folder sizes on Windows, helping you understand your storage consumption better. It’s versatile, allowing you to assess single folders or delve into subdirectory sizes. You can even filter results based on criteria like creation dates, enhancing your file and folder management. By using these commands, you can efficiently optimize your Windows experience and take control of your storage space.