Paypal Donate

Check SMART hard-disk status

File

This script will query the SMART status of a hard-disk for reports of any imminent failures.  It takes a list of computers (in a text file) and will both save a report and show the results in the command window.

If SMART isn't enabled (and it's surprising how many new computers appear to have it disabled in the BIOS), then the status can't be queried - this will also be reported so that you can turn SMART on!

To report for the local computer, just use a text file with a "." on one line ("." signifies to WMI to connect to the local computer).

' Script written by David Barrett
' Copyright 2009
' http://www.cedit.biz/
'
This script is licensed under the Creative Commons
' Attribution 2.5 Licence
' http://creativecommons.org/licenses/by/2.5/
'

' You are free to use it for both personal and
' commercial purposes, so long as full attribution
' is given to the author (David Barrett).
'
' This notice must not be removed
'
'
option explicit
dim strComputerList, strResults, strSaveReportAs

strComputerList="E:\computers.txt"
strSaveReportAs="E:\report.txt"

dim objFSO, objF

set objFSO=CreateObject("Scripting.FileSystemObject")

' Read list of computers and get reports
set objF=objFSO.OpenTextFile(strComputerList,1)
while not objF.AtEndOfStream
    strResults=strResults & CheckSMART(objF.ReadLine, true) & vbcrlf
wend
objF.Close

' Now save report to text file
set objF=objFSO.OpenTextFile(strSaveReportAs, 8, true)
objF.Write strResults
objF.Close



function CheckSMART(strComputer, blnEcho)
    dim objWMI, objInstances, objInstance
    dim strReport
    On Error Resume Next

    Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
    if strComputer="." then strComputer="Local machine" ' Give friendly name for local computer
    Set objInstances = objWMI.InstancesOf("MSStorageDriver_FailurePredictStatus",48)
    if Err.Number0 then
        strReport="Could not connect to " & strComputer & vbCrLf
        strReport=strReport & Err.Description
        Err.Clear
    else
        For Each objInstance in objInstances
            With objInstance
                if not .Active then
                    strReport=strReport & strComputer & " SMART not active"
                elseif .PredictFailure then
                ' Failure predicted for this drive
                    strReport=strReport &  strComputer & " drive predicted to fail: "
                    strReport=strReport & .InstanceName & vbCrLf
                    strReport=strReport &  "Reason: " & .Reason
                else
                    strReport=strReport &  strComputer & " reports no current hard-disk problems."
                end if
            End With
        Next
    end if
    On Error Goto 0
    if blnEcho then wscript.echo strReport
    CheckSMART=strReport
end function
Copyright © 2009 www.cedit.biz. All rights reserved.