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

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....