Skip to content

Get-DirectorySize : Quickly finding what was eating all my hard drive space with PowerShell

One of my machines was inexplicably running out of hard drive space on it’s OS drive. I cleared it down a couple of times, and within a day or two it was full again

image

 

I turned to the tool that solves all problems, PowerShell. I wrote a quick and dirty script to take a starting directory, and recurses all directories, measuring the size for each one, You can find the script on my Github here:

https://github.com/tomarbuthnot/Get-DirectorySize

It does error on some protected paths, even when run from PowerShell as an administrator, I think you could get around that by running it as a service account, but I didn’t need to in this case.

I checked the whole drive, which took some time, and found the following:

image

Hmm, that’s a little on the large side:

image

It seems I hit this bug, which causes the windows.edb which is the windows search cache, to bloat out.

A quick rebuild and so far it seems fine.

image

 

I’m sure I could have found a tool to map out the directory size/could have searched for single large files, but it’s nice to have a tool as flexible as PowerShell to quickly nock up a script to help you troubleshoot issues

Published inPowerShell

3 Comments

  1. Tom Tom

    You should try SpaceSniffer. It’s not PowerShell, but it’s still cool! It maps your drive out into coloured blocks so you can really easily see where the space is going. Good for those of us with big VMs and small SSDs!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.