Get-FolderSize and learning the shell


Well it’s Sunday and blog posting time.  I wanted to continue my pattern of going over a custom function every week but I thought this week I’d try and also focus on why you should learn powershell.  If you already rock at the shell you can skip the article and get to the function here.

I wrote the function, Get-FolderSize, to do a pretty simple task, get the total size of a folder.  Powershell does a lot of thing really well but sometimes it makes “simple” things a little overly complex.  That is one of the big reasons I write my own functions, to add easy to use functionality, I load a function like this in my profile and it’s always available.  When I was looking for a way to find the size of a folder I came across this article by the scripting guys.  I’d suggest you take a look at that article for a detailed explanation of how powershell handles calculating the total size of a directory.  The overall point is that to get the size of a folder you need to measure the length of every single file in a directory.

I’ve posted a link to the function and to the logic so I won’t spend a ton of time talking about how it works.  The Scripting guys are better at that than I am anyway.  The thing I wanted to talk about was how learning to do something like this is useful to understanding how the OS really works.  I found that going through and figuring out how to calculate the size of every file in a directory helped me get a deeper understanding of how windows works.  That, in my opinion, is one of the best things about learning powershell.  Windows Administrators can easily get stuck into a pattern where we learn how to use wizards and applications but we fail to learn what’s going on under the covers.  PowerShell helps demystify the OS and even a simple thing like getting the size of a folder can reveal a lot.

Regardless, that’s all I have for this week, I hope you enjoyed it.  here’s a link to my function, in case you missed it:

And here’s where you can find all the other things I’ve published in the gallery:

I hope you like the script, please take the time to rate it and post comments and questions.  It helps to see what people think about stuff like this.

This entry was posted in PowerShell and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s