Finding the sizes for subfolders in a parent folder

I came up with this to find the sizes of each subfolder (one level) in a parent folder. The primary use case is figuring out which users are using excessive amounts of space in their personal folders on a network share, but it’s not limited to that.
This will end up with data suitable for discussing with people (because most of the GUI tools give me pretty pictures, but aren’t really designed for sharing the results with your line manager or the individual users when you have the conversation about cleaning house).

It will report the size both in bytes (for sorting) and in GB/MB/KB/bytes (for ease of communicating), and will also identify the single largest file in each of the subfolders. Useful for when someone has zipped up their entire user folder on their computer and uploaded it to their personal folder…

Note that this works very well with the excellent ImportExcel module mentioned in the Scripting Guys blog, and available from the PowerShell Gallery.

In this case, you would use a command line like this:
.\Get-FolderSize.ps1 -path \\Server\Share\Path | Export-Excel -path c:\temp\pathreport.xlsx -TableName path -TableStyle Medium13 -AutoSize

Leave a Reply

Your email address will not be published. Required fields are marked *