Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've already know a sharespace path: \sharespace\test1

I used this line to get the latest update folder under this path:

$lastbuild=get-childitem $var.droppath.TrimEnd()|where-object {$ -match "10."} |Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1

what I got is \\sharespace\test1\10.0.1212.1

How can I get this folder's size? I used the following code, but only get the totalsize of its parent path\\sharespace\test1


$fsobuild = new-Object -com Scripting.FileSystemObject

$dobuild = $fsobuild.getdrive("u:")

Write-host "Size of latestbuild:"

share|improve this question
up vote 1 down vote accepted

This looks like exactly what you need: Scripting Guy article on getting folder size

I think it's important to note that powershell can typically handle UNC paths natively, so there's no need to map a drive. You should be able to do something like this:

$fsobuild = new-Object -com Scripting.FileSystemObject
"{0:N2}" -f (($fsobuild.GetFolder($lastbuild.Fullname).Size) / 1MB) + " MB"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.