Display a drive space report for multiple computers. This HTA can check the drives of multiple computers and produce a HTML report that will highlight any drives that are low on free space. The HTA also generates a CSV version of the report.
The Drive Space Report is a GUI script that allows you to view the disk drives and free space on several computers. Just enter the computer name or IP Address, one per line and click the “Generate Report” button to display the report. Click the “Download Report (CSV)” button to save the report in CSV (comma separated) format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <head> <title>WiseSoft Drive Space Report</title> <hta:application applicationname="WiseSoft Drive Space Report" scroll="yes" singleinstance="yes" windowstate="normal"> <style type="text/css"> body { background-color: #F2F2F2; font: bold 10pt arial,sans-serif; color:#787878; margin:0px; } table { width: 400; border: 2px solid; border-collapse: collapse; border-color: #696969; } th { border: 1px dotted #111111; border-color: #787878; color: #FFFFFF; font: bold 12pt arial,sans-serif; background-color: #787878; text-align: left; } td { border: 1px dotted #111111; border-color: #787878; font: bold 10pt arial,sans-serif; color: #787878; } .neutral { background-color: #FFFFE0; color: #787878; } .good { background-color: green; color: white; } .warning { background-color: yellow; color: black; } .critical { background-color: red; color: black; } .tableHead td { padding: 5px; font: bold 14pt arial,sans-serif; background-color: #787878; text-align: center; color: white; } h1 { background-color: #787878; color: white; font: bold 20pt arial,sans-serif; text-align: center; } </style> </head> <script language="VBScript"> OPTION EXPLICIT ' ********** Constants ********** CONST bytesToMB = 1048576 CONST bytesToGB = 1073741824 CONST bytesToTB = 1099511627776 CONST warningLevel = 20 ' < 20% = warning (yellow) CONST criticalLevel = 10 ' < 10% = critical (red) CONST goodLevel = 50 ' > 50% = good (green) ' ********************************** SUB GetDriveReportsHTML DIM html, strComputer,strComputers strComputers = txtComputers.value FOR EACH strComputer in SPLIT(strComputers,CHR(13)) strComputer = TRIM(REPLACE(strComputer,CHR(10),"")) IF strComputer <> "" THEN html = html & GetDriveReportHTML(strComputer) END IF NEXT report.InnerHTML = html END SUB FUNCTION ConvertToDiskUnit(BYVAL value) IF (value/bytesToTb) > 1 THEN ConvertToDiskUnit = ROUND(value / bytesToTB,1) & " TB" ELSEIF (value/bytesToGb) > 1 THEN ConvertToDiskUnit = ROUND(value / bytesToGB,1) & " GB" ELSE ConvertToDiskUnit = ROUND(value / bytesToMB,1) & " MB" END IF END FUNCTION FUNCTION GetDriveReportHTML(BYVAL strComputer) DIM objWMIService, objItem, colItems DIM strDriveType, strDiskSize, htmlDriveReport ON ERROR RESUME NEXT SET objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2") IF Err.Number <> 0 THEN GetDriveReportHTML = "<span class=""critical"">Error connecting to '" & strComputer & "'</span><br/><br/>" Err.Clear ON ERROR GOTO 0 EXIT FUNCTION END IF ON ERROR GOTO 0 SET colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3") htmlDriveReport = "<table><tr class=""tableHead""><td colspan=""5"">" & strComputer & _ "</td></tr><tr><th>Drive</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>" FOR EACH objItem in colItems DIM pctFreeSpace,strFreeSpace,strusedSpace, cssClass pctFreeSpace = ROUND(((objItem.FreeSpace / objItem.Size) * 100),1) strDiskSize = ConvertToDiskUnit(objItem.Size) strFreeSpace = ConvertToDiskUnit(objItem.FreeSpace) strUsedSpace = ConvertToDiskUnit(objItem.Size-objItem.FreeSpace) IF pctFreeSpace < criticalLevel THEN cssClass = "critical" ELSEIF pctFreeSpace < warningLevel THEN cssClass = "warning" ELSEIF pctFreeSpace > goodLevel THEN cssClass = "good" ELSE cssClass = "neutral" END IF DIM strChart strChart = "<div style=""width=100%;""><span style=""width=" & 100-pctFreeSpace & _ "%;background-color:blue;""></span><span style=""width=" & pctFreeSpace & _ "%;background-color:#FF00FF;""></span></div>" htmlDriveReport = htmlDriveReport & "<tr><td>" & objItem.Name & strChart & "</td><td>" & _ strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _ strFreeSpace & "</td><td class=""" & cssClass & """>" & pctFreeSpace & "%</td></tr>" NEXT htmlDriveReport = htmlDriveReport + "</table></br>" GetDriveReportHTML = htmlDriveReport END FUNCTION SUB GetDriveReportsCSV DIM csv, strComputer,strComputers, path strComputers = txtComputers.value csv = "Computer,Drive,Size,Used,Free,Free(%)" FOR EACH strComputer in SPLIT(strComputers,CHR(13)) strComputer = TRIM(REPLACE(strComputer,CHR(10),"")) IF strComputer <> "" THEN IF csv <> "" THEN csv = csv & VbCrLf END IF csv = csv & GetDriveReportCSV(strComputer) END IF NEXT path = INPUTBOX("Enter FileName:","Enter FileName","MyDriveReport.csv") IF path = "" THEN EXIT SUB END IF WriteTextFile csv, path END SUB FUNCTION GetDriveReportCSV(BYVAL strComputer) DIM objWMIService, objItem, colItems DIM strDriveType, strDiskSize, csvDriveReport ON ERROR RESUME NEXT SET objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2") IF Err.Number <> 0 THEN GetDriveReportCSV = strComputer & ",Error,Error,Error,Error,Error" Err.Clear ON ERROR GOTO 0 EXIT FUNCTION END IF ON ERROR GOTO 0 SET colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3") FOR EACH objItem in colItems DIM pctFreeSpace,strFreeSpace,strusedSpace, cssClass pctFreeSpace = ROUND(((objItem.FreeSpace / objItem.Size) * 100),1) strDiskSize = ConvertToDiskUnit(objItem.Size) strFreeSpace = ConvertToDiskUnit(objItem.FreeSpace) strUsedSpace = ConvertToDiskUnit(objItem.Size-objItem.FreeSpace) IF pctFreeSpace < criticalLevel THEN cssClass = "critical" ELSEIF pctFreeSpace < warningLevel THEN cssClass = "warning" ELSEIF pctFreeSpace > goodLevel THEN cssClass = "good" ELSE cssClass = "neutral" END IF IF csvDriveReport <> "" THEN csvDriveReport = csvDriveReport & VbCrLf END IF csvDriveReport = csvDriveReport & strComputer & "," & objItem.Name & "," & _ strDiskSize & "," & strUsedSpace & "," & _ strFreeSpace & "," & pctFreeSpace & "%" NEXT GetDriveReportCSV = csvDriveReport END FUNCTION SUB WriteTextFile(BYVAL txt,BYVAL path) DIM objFSO, objTextFile SET objFSO = CREATEOBJECT("Scripting.FileSystemObject") IF objFSO.FileExists(path) THEN IF MSGBOX("Warning: file already exists! Overwrite file?",vbYesNo+vbQuestion,"Overwrite File?") = vbNo THEN EXIT SUB END IF END IF SET objTextFile = objFSO.CreateTextFile(path) objTextFile.Write(txt) objTextFile.Close MSGBOX "Created '" & path & "' Report",vbOKOnly+vbInformation END SUB </script> <body> <h1 style="margin-bottom: 0px;"> Drive Space Report</h1> <div style="text-align: right; font: bold 8pt arial,sans-serif; color: #787878;"> By David Wiseman, <a target="_blank" href="http://www.wisesoft.co.uk">www.wisesoft.co.uk</a> </div><br /> <div style="text-align: center;"> Enter names of computers (one line per computer):<br /> <textarea name="txtComputers" rows="4" cols="50"> localhost . 127.0.0.1 </textarea><br /> <input style="font-weight:bold;" onclick="GetDriveReportsHTML" type="submit" value="Generate Report"></input> <input onclick="GetDriveReportsCSV" type="submit" value="Download Report (CSV)"></input> <br /> <br /> </div> <div style="text-align: center;" id="report"> </div> </body> </html> |