It's nice to have a script that would calculate some folders in MB like the commerial Treesize

I found a script on Wordpress that would just do that. I had to correct it somewhat but here is the result:

$TotalFoldSZ=0 #total folder size
$foltree=get-childitem “\\server\homedrives\” #Which fold size you wish to check out, this can be easily turn into user’s by using read-host

foreach ($folt in $foltree) {

                if($folt.mode -match “d”) { 
#I used mode attribute to get only directories, so what about files in the parent directory…hmm coming to in…:-)

$fsz=((get-childItem $folt.fullname -recurse | Measure-Object -Property Length -sum).sum)/1MB 

#Got the size in MB

$FSize=”{0:N2}” -f $fsz 

#Formatted to two decimals

write-host $ $fsize MB 

# wrote to screen FolderName,FolderSize


#To get the total folder size
$filesize=(($foltree | measure-object -Property length -sum).sum)/1MB 
#This is where I check if there are files present in the parent folder. If there are #only files then I will get folder size zero, not to miss that out, I’ve to include it.
$fsizeMB=”{0:N2}” -f $filesize 
#Formatted it get in MB Write-host Total Size of Folder is ($TotalFSZ+$fsizeMB) MB #here finally I add each folder size and files inside parent folder.

On Me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License