Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 {$_.name -match "10."} |Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1
$lastbuild.fullname.TrimEnd()

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

$mapbuild.mapNetworkDrive("u:",$lastbuild.fullname.TrimEnd())

$fsobuild = new-Object -com Scripting.FileSystemObject

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

Write-host "Size of latestbuild:"

$dobuild.totalsize
share|improve this question
add comment

1 Answer

up vote 0 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
add comment

Your Answer

 
discard

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.