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 have an external disk that is connected to a LAN network.
I want to find the disk usage of a directory on the disk from a script. I looked at power shell and SysInternals tools but couldn't find any solution. Any ideas?


share|improve this question
up vote 8 down vote accepted

Powershell makes it possible in the following way:

Size in MB

"Folder use {0:0,0.00} MB" -f (((Get-ChildItem -R C:\TEMP | measure-object length -Sum ).Sum / 1MB)

Size in GB

"Folder use {0:0,0.00} MB" -f (((Get-ChildItem -R C:\TEMP | measure-object length -Sum ).Sum / 1GB)

Maybe in TB

"Folder use {0:0,0.00} MB" -f (((Get-ChildItem -R C:\TEMP | measure-object length -Sum ).Sum / 1TB)
share|improve this answer
This works well, "Folder use 121.79 MB." You can also use 1KB in place of 1024. – Bratch Sep 14 '09 at 16:15

You could try any of the TreeSize type tools, for instance

share|improve this answer
Thanks for all the other posts. The answers where good but this one is exactly what I need. – Ohad Horesh Sep 15 '09 at 7:00

There is also a Microsoft Tool called Diruse.

D:\Webmaster\cmd>diruse.exe C:\temp /M /*

Size (mb)  Files  Directory
   501.75    138  SUB-TOTAL: C:\TEMP\Garbadge
   501.75    138  TOTAL: C:\TEMP\Garbadge

You can find more about diruse here

share|improve this answer

Cygwin's du will do the trick as well.

$ /bin/du 'C:\WINDOWS\system32' | sort -rn | head -20
1104392 C:\WINDOWS\system32
194127  C:\WINDOWS\system32/dllcache
61675   C:\WINDOWS\system32/spool
61284   C:\WINDOWS\system32/config
57336   C:\WINDOWS\system32/ReinstallBackups
54572   C:\WINDOWS\system32/ReinstallBackups/0020/DriverFiles
54572   C:\WINDOWS\system32/ReinstallBackups/0020
51952   C:\WINDOWS\system32/mui
51590   C:\WINDOWS\system32/wbem
48765   C:\WINDOWS\system32/spool/drivers
48573   C:\WINDOWS\system32/spool/drivers/w32x86
43233   C:\WINDOWS\system32/spool/drivers/w32x86/3
33102   C:\WINDOWS\system32/drivers
21610   C:\WINDOWS\system32/wbem/Repository
21609   C:\WINDOWS\system32/wbem/Repository/FS
12030   C:\WINDOWS\system32/spool/XPSEP
10244   C:\WINDOWS\system32/wbem/AutoRecover
9890    C:\WINDOWS\system32/CatRoot
9889    C:\WINDOWS\system32/CatRoot/{F750E6C3-38EE-11D1-85E5-00C04FC295EE}
9770    C:\WINDOWS\system32/CatRoot2

There you go: the twenty largest directory sizes (in K).

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.