Search This Blog

Tuesday, October 26, 2010

Script to find folder size

We are doing home drive migration project where in we need to find out what is the size of users' home drive. To make this task more efficient and fast we used powershell to achieve this. Small code but works great

# declaring the parameter so we can invoke parameter at command line

write-host size of $path is
# just info

$colItems = (Get-ChildItem $path -recurse | Measure-Object -property length -sum)
# *get-childItem will get all the folders and files under given path, recurve will check for subfolder and files, then pipe to measure object which will sum all the size *#

"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
# 0:N2 will parse the data to two decimal place, and then format from bytes to MB.

The script can be used like this
>.\foldersize.ps1 "\\ServerName\Share$"

No comments:

Post a Comment