Wednesday, February 9, 2011

Script to get local drive utilization

'get local drive utilization
dim objFSO,collDrv
dim fs,d

set objFSO=wscript.CreateObject("Scripting.FileSystemObject")
set collDrv=objFSO.Drives

  for each drv in collDrv
        if drv.DriveType=2 then  'check fixed drives only
                Set fs = CreateObject("Scripting.FileSystemObject")
                Set d = fs.GetDrive(fs.GetDriveName(drv))
                 t = FormatNumber(d.TotalSize/(1024*1024), 0)
                 f = FormatNumber(d.FreeSpace/(1024*1024), 0)
                 u = 100-FormatNumber(f/t,2)*100
                 s= s & drv & "  " & drv.VolumeName & " (" & drv.FileSystem & ")" & vbtab & t & " MB 
                      Total"& vbtab & f & " MB Free" & vbtab &  u & "% Utilized" & vblf
       end if
  next

wscript.echo s

set objFSO=Nothing
set collDrv=Nothing
set fs=Nothing
set d=Nothing
wscript.quit

No comments: