Home > Scripting, VB Scripting, Windows Server > Free Disk Space Report:

Free Disk Space Report:

Whether its for daily checks or a for a once off report this handy little script allows you to connect to as many servers as you like, query all local drives, report the capacity of the drives and the free space available. It writes all this information to a snazzy HTML file that is saved on the local disk.

This is a vbs file and uses a servers.txt (keep the txt file in the same location as the script) file as a reference for each of the servers you wish to connect to. I’ve tested this on up to 30 servers at a time with flawless output. This script can be run as a schedueled task and accross psexec. Just one point to note, if it is being executed from a UNC path, map the drive first or it will fail to lookup servers.txt

I use this script as a daily check to check up on all the file servers and exchange servers in the morning.

Heres an example of the html file you are finished with.

Server Utilization Report

Server1 Drive Utilization

C:\ Size: 20,003 MB Free: 8,791 MB |||||||||||||||||||||||||||||||||||||||||||| 43.95% Free
E:\ Size: 10,000 MB Free: 3,715 MB ||||||||||||||||||||||||||||||||||||| 37.15% Free

Created 26/02/2008 12:14:12 by morgan_a

For the code, click more…

‘Andrew Morgan February 2008
‘connects to a device and lists all capacity & free space

Dim objService,objLocator
Dim objFSO, objOutFile,objFile1
Dim objNetwork

‘Get Date Vars
strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)

On Error Resume Next

‘Location of HTML file that will be created (dont use network shares unless drive is mapped)
htmFile=”c:\” & strMonth & “-” & strDay & “-” & strYear & “.htm”

‘Name of servers text file (must be kept in the same directory as the script)

Const myGreen=”008000″
Const myRed=”FF0000″
Const myYellow=”FFD700″

set objNetwork=CreateObject(“wscript.network”)
Set objFSO=CreateObject(“Scripting.FileSystemObject”)
Set objOutFile=objFSO.CreateTextFile(htmFile)
Set objFile1=objFSO.OpenTextFile(serverlist,1)

‘Write Lead in of htm file
‘Change the next line to change the header
objOutfile.WriteLine “<HTML><HEAD><TITLE>Server Logical Drive Utilization</TITLE></HEAD>”
‘objOutfile.WriteLine “<BODY BGCOLOR=” & CHR(34) & “FFFFF” & CHR(34)& “>”
objOutfile.WriteLine “<BODY BGCOLOR=FFFFF>”
objOutfile.WriteLine “<H1>Server Utilization Report</H1></P>”

Do While objFile1.AtEndOfStream<>True

If strServer<>”” Then

objOutfile.WriteLine “<BR>” & UCASE(strServer) & ” Drive Utilization<BR><HR>”

‘Create locator
Set objLocator = CreateObject(“WbemScripting.SWbemLocator”)
If Err.Number then
objOutfile.WriteLine “Error ” & err.number & ” [0x” & CStr(Hex(Err.Number)) & “] occurred in creating a locator object.<BR>”
If Err.Description <> “” Then
objOutfile.WriteLine “Error description: ” & Err.Description & “.</p>”
End If
End If

‘Connect to the namespace which is either local or remote
‘Uncomment next line for debugging
‘wscript.echo “Connecting to ” & “(“&strServer&”,root\cimv2)”

Set objService = objLocator.ConnectServer (strServer,”root\cimv2″)
ObjService.Security_.impersonationlevel = 3
If Err.Number then
objOutfile.WriteLine “Error ” & err.number & ” [0x” & CStr(Hex(Err.Number)) &”] occurred in connecting to server ” & UCASE(strServer) & “.<BR>”
objOutfile.WriteLine “Make sure you are using valid credentials that have administrative rights on this server.</P>”
If Err.Description <> “” Then
objOutfile.WriteLine “Error description: ” & Err.Description & “.</P>”
End If

objOutfile.WriteLine “<Table Border=0 CellPadding=5>”
For Each item In objService.InstancesOf(“Win32_LogicalDisk”)
If item.DriveType=3 Then ‘get local drives only
Size=FormatNumber(item.Size/1048576,0) & ” MB”
Free=FormatNumber(item.FreeSpace/1048576,0) & ” MB”

objOutfile.WriteLine “<TR>”
objOutfile.WriteLine “<TD>” &item.DeviceID & “\ </TD>”
objOutfile.WriteLine “<TD>Size: ” & Size & “</TD>”
objOutfile.WriteLine “<TD>Free: ” & Free & “</TD>”
objOutfile.WriteLine “<TD><B><Font Size=+1 Color=” & GraphColor(graph) & “>” & String(Graph,”|”) & “</Font></B></TD>”
objOutfile.WriteLine “<TD>” & PerFree & ” Free</TD></TR>”
End If
objOutfile.WriteLine “</Table>”
End If
End If

objOutfile.WriteLine(“</P><Font Size=-1><B><I> Created ” & NOW & ” by ” & objNetwork.UserName & “</I></B></Font>”)
‘commented echo back
‘wscript.Echo VBCRLF & “See ” & htmfile & ” for results”
Function GraphColor(graph)
On Error Resume Next
If Graph > 30 Then
Exit Function
End If
If Graph < 10 Then
End If
End Function
Sub CheckResponse(response)
If response=”” Then
wscript.Echo “You didn’t enter anything in the last input box or you cancelled the script.”
End If
End Sub


  1. vinod vasu
    May 24, 2011 at 4:50 am

    Nice tool, its work just great

  2. alan
    April 19, 2013 at 2:50 pm

    couldnt seen to run this im noob is this .hta or ,vbs

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: