Disk Space VB Script

VB Script for getting disk space on the servers: 

strComputer = "."

Dim x

x=0

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list.txt")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("rs550mblgw02.htm",8)

objFile.WriteLine "<html>" & VbCrLf & "<body id=bdy>" & VbCrLf


objFile.WriteLine "<table border=1 width=100%>" & VbCrLf & "<tr> <td colspan=1 align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'> Disk Space Report </fond></b></td> <td colspan=4 align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'> Last Updated  " & Now & " GMT</font></b></td> </tr>" 
objFile.WriteLine "<tr>" & VbCrLf & "<td align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'>Server Name </font></b></td>" & "<td align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'>Disk ID </font><b></td>" & VbCrLf & "<td align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'>Total Space</font></b></td>" & "<td align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'> FreeSpace <?font></b></td>" & "<td align=left bgcolor=#fffff6><b><font face='Calibri' size='3' color='black'> % FreeSpace </font></b></td>" & VbCrLf & "</tr>" & VbCrLf

do while not listFile.AtEndOfStream 
    strComputer =  listFile.ReadLine()

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DeviceID = 'E:'")

If Err.Number =0 Then

For Each objDisk in colDisks
         
    'Select Case objDisk.DriveType
        'Case 1
            'Wscript.Echo "No root directory. Drive type could not be " _
                '& "determined."
        'Case 2
            'Wscript.Echo "DriveType: "& vbTab &  "Removable drive." &  objDisk.DeviceID
        'Case 3

If Round((objDisk.Freespace/ objDisk.Size ) * 100 , 2 ) <= 25 Then
    objFile.WriteLine "<tr>" & VbCrLf

'If x=0 Then
objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>" & strComputer & "</font></b></td>" & VbCrLf
'x=1
'Else
'objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>          </font></b></td>" & VbCrLf

'End If
   
    objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & objDisk.DeviceID & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.Size/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.FreeSpace/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='red'>" & Round((objDisk.Freespace/ objDisk.Size) * 100 , 2) & "</font></b></td>" & VbCrLf
    objFile.WriteLine "</tr>" & VbCrLf

Else

'If x=0 Then
objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>" & strComputer & "</font></b></td>" & VbCrLf
'x=1
'Else
'objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>          </font></b></td>" & VbCrLf

'End If

objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & objDisk.DeviceID & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.Size/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.FreeSpace/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='green'>" & Round((objDisk.Freespace/ objDisk.Size) * 100 , 2) & "</font></b></td>" & VbCrLf
    objFile.WriteLine "</tr>" & VbCrLf

End If
        'Case 4
            'Wscript.Echo "DriveType: "& vbTab &  "Network disk." &  objDisk.DeviceID     
        'Case 5
            'Wscript.Echo "DriveType: "& vbTab &  "Compact disk." &  objDisk.DeviceID     
        'Case 6
            'Wscript.Echo "DriveType: "& vbTab &  "RAM disk."  &  objDisk.DeviceID 
        'Case Else
            'Wscript.Echo "Drive type could not be determined."
    'End Select

Next

'x=0
Set colDisks2 = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")

For Each objDisk in colDisks2
If Round((objDisk.Freespace/ objDisk.Size ) * 100 , 2 ) <= 10 Then
    objFile.WriteLine "<tr>" & VbCrLf


'If x=0 Then
'objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>" & strComputer & "</font></b></td>" & VbCrLf
'x=1
'Else
objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>          </font></b></td>" & VbCrLf

'End If

    objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & objDisk.DeviceID & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.Size/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.FreeSpace/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='red'>" & Round((objDisk.Freespace/ objDisk.Size) * 100 , 2) & "</font></b></td>" & VbCrLf
    objFile.WriteLine "</tr>" & VbCrLf

Else

'If x=0 Then
'objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>" & strComputer & "</font></b></td>" & VbCrLf
'x=1
'Else
objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='black'>          </font></b></td>" & VbCrLf

'End If
objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & objDisk.DeviceID & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.Size/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8> <font face='Calibri' size='2' color='black'>" & Round(objDisk.FreeSpace/ (1024 * 1024 * 1024 ) , 2 ) & "</font> </td>" & VbCrLf
            objFile.WriteLine "<td align=left bgcolor=#F3F1F8><b><font face='Calibri' size='2' color='green'>" & Round((objDisk.Freespace/ objDisk.Size) * 100 , 2) & "</font></b></td>" & VbCrLf
    objFile.WriteLine "</tr>" & VbCrLf

End If

Next
Else

objFile.WriteLine strComputer & vbtab & "Error"

Err.Clear()

End If

x=0

loop

objFile.Close

Comments

Popular posts from this blog

Base 64 encoding and decoding

LINQ Queries with GROUP BY, INNER JOIN, COUNT and SUM: Examples

How to write Custom delete Confirmation Modal for Kendo Grid in MVC: