Powershell: Get-SubFolderSize


image 

On every home directory will be a  folder called Files. I was curious how big these folders are. So this is why I created the following Powershell script:

function Get-Foldersize{
  param([string]$StartFolder,
        [string]$SubFolder)
  
  $Dirs = Get-ChildItem -path $StartFolder\* -Recurse -Include $SubFolder 
    
  foreach($Dir in $Dirs){
  $objFSO = New-Object -com  Scripting.FileSystemObject
  "$Dir = " + "{0:N2}" -f (($objFSO.GetFolder("$Dir").Size) / 1MB) + " MB" 
  }
}

Get-FolderSize C:\Users Files

 

The output of the script will look like this:

image

Here are some pictures (as hard evidence 😉 ) of the folder properties:

image

Source: http://www.microsoft.com/technet/scriptcenter/

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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