troubleshooting Question

Checking disk space errors vbscript

Avatar of martin05
martin05 asked on
Visual Basic ClassicVB Script
7 Comments1 Solution265 ViewsLast Modified:
Hi
I have a little bit of VB which checks diskspace

Sub chkdiskspace (StrComp)

If dbgTitle <> "" Then objdiv.innerhtml = strMsg & "<font face=" & strFontStyle & " color=" & strFontColor2& ">" _
& "Checking disk space...</font><br>"
l.writeline Time & " - Checking disk space."
'==Connect to winmgmts==
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrComp & "\root\cimv2")


'==Run query to identify logical disks==
Set colDisks = objWMIService.ExecQuery _
("Select Freespace, Name, Size from Win32_LogicalDisk where DriveType = 3")
Call fctErrorHandling

'==Write header to htm file==
res.Writeline ("<table border=1 width=100% cellspacing=0 cellpadding=3>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor1 & " colspan=6 width=200>")
res.Writeline ("<p align=left>")
res.Writeline ("<b><font face=" & strFontStyle & " size=2 color=" & strFontColor2 & ">Disk space</font></b></p>")
res.Writeline ("</th>")
res.Writeline ("</tr>")
res.Writeline ("<tr>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Disk ID</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Percentage Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Free Space</font></th>")
res.Writeline ("<th bgcolor=" & strHDRColor2 & " width=60><font face=" & strFontStyle & " color=" & strFontColor1 & " size=1>Total Space</font></th>")
res.Writeline ("</tr>")

'==Write results to htm file==
For Each objDisk In colDisks
Call bgcolor
res.Writeline ("<TR bgcolor='" & strbgcolor & "'><TD><font face=" & strFontStyle & " color=" & strFontColor2 & " size=1> " & objDisk.Name & strendline)

If (objDisk.Freespace/objDisk.Size)*100 <=10 Then

fontcol = "#FF0000"
Else
fontcol = "#666666"
End If
If objDisk.Freespace > 10000 Then
    strUnit = "GB"
    strDiskSize = FormatNumber(objDisk.Freespace / 1073741824,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1073741824,2)
ElseIf objDisk.Freespace < 1 Then
    strUnit = "KB"
    strDiskSize = FormatNumber(objDisk.Freespace / 1024,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1024,2)
ElseIf objDisk.Freespace < 1000 Then
    strUnit = "MB"
    strDiskSize = FormatNumber(objDisk.Freespace/1048576,2)
    strDiskTotal = FormatNumber(objDisk.Size / 1048576,2)
End If
strPercentFree = Round((objDisk.Freespace/objDisk.Size)*100,2)


If strPercentFree < intFreeSpaceThreshold Then
'wscript.echo strPercentFree
strSpace = strSpace & objDisk.Name & " - " & Round((objDisk.Freespace/objDisk.Size)*100,2) _
& "% free (" & FormatNumber(objDisk.Freespace / 1073741824,2) & "Gb remaining)<br>"
    res.Writeline ("<TD><font face=" & strFontStyle & " color='red' size=1>" & strPercentFree & "%" & strendline)
    blnErrors = True
    blnDiskSpace = True
Else
    res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strPercentFree & "%" & strendline)
End If

res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskSize & strUnit & strendline)
res.Writeline ("<TD><font face=" & strFontStyle & " color=" & strfontcolor2 & " size=1>" & strDiskTotal & strUnit & strendline & "</TR>")

Next

 the problem i have is I need to omit some drives from the check as they are returning NULL values
can anyone see from the code an easy way to do it ?

thanks


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros