By David Wiseman (Administrator)Created 14 Sep 2007
My Rating:
Vote
Rating:
Not Rated
Views:33591
Downloads:1176

Disk Space Usage Report

Language:  VBScript

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 Unknown Windows NT Unknown
Vista Unknown Windows 2008 Unknown
Description

Generate a report that contains total disk size, used disk space, free disk space and percentace free disk space.


Notes
The script generates a tab-seperated report that can be viewed in notepad/excel. 
Code

Line Numbers: On  Off      Plain Text
Option Explicit

const strComputer = "."
const strReport = "c:\diskspace.txt"


Dim objWMIService, objItem, colItems
Dim strDriveType, strDiskSize, txt

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
txt = "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
For Each objItem in colItems
	
	DIM pctFreeSpace,strFreeSpace,strusedSpace
	
	pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
	strDiskSize = Int(objItem.Size /1073741824) & "Gb"
	strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
	strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
	txt = txt & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf

Next

writeTextFile txt, strReport
wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt

' Procedure to write output to a text file
private sub writeTextFile(byval txt,byval strTextFilePath)
	Dim objFSO,objTextFile
	
	set objFSO = createobject("Scripting.FileSystemObject")

	set objTextFile = objFSO.CreateTextFile(strTextFilePath)

	objTextFile.Write(txt)

	objTextFile.Close
	SET objTextFile = nothing
end sub

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
JeDi MaStEr
United States
Posted On: 5/7/2008 3:44:45 PM [Edited 5/7/2008 3:45:04 PM]

perfect saved me alot of time. this did exactly what i needed. thanks Admin

Vimal_Bhatt
Posted On: 5/14/2009 6:37:17 AM

Thanks Admin its real very useful for me at very important time,, thanks a lot....

aravind_jammy
Posted On: 2/3/2015 10:35:12 PM [Edited 2/3/2015 11:30:51 PM]

hi, works perfect.. but i am running this on task scheduler on daily basis...here comes the problem...every time after the VBS runs it gives a pop up..once i click the OK button then it writes on to the file specified...how to over come this ..I want the propmt to be opened but file should be written on continous basis. got it removed :wscript.echo "Report written to " & strReport & vbcrlf & vbcrlf & txt thanks

Prerna
Posted On: 3/6/2015 3:13:24 AM

Thank you for excellent script. Is there any way to display particular folder size of any drive?