Pre-Flight Checks – SMART Check

While writing my last entry titled Pre-Flight Checks – Wireless Connectivity, I figured I would go ahead and post this script that does a pre-flight check to check the S.M.A.R.T. status of the hard drive.  S.M.A.R.T. stands for Self_Monitoring Analysis & Reporting Technology and it allows the machine to effectively predict impending failures of the hard drive.

To check this status of the hard drive, I am looking at the Win32_DiskDrive class.  This class has an object called Status that keeps track of, oddly enough, the status of the hard drive.  The status we are looking for is ‘OK’.  For more information on the Win32_DiskDrive class, or Status, click here.

As always, I am using the zero touch script format in a custom .wsf file.  For more information on custom ZTI scripts, please visit here.

 Option Explicit
Dim iRetVal
Dim oWMI, oConn, oRs
Dim strComputer, sSmartIsClear, sSmartStatus, sSMART, DQ
Dim colDisks, disk


DQ = CHR(34)

'// End declarations
'// Main routine
On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0
'// Function: ZTIProcess()
'// Input: None
'// Return: Success - 0
'// Failure - non-zero
'// Purpose: Perform main ZTI processing
Function ZTIProcess()
     iRetVal = Success
     ZTIProcess = iRetval
     Const scriptVersion = "1.0"

strComputer = "."

' Create objects
Set oRs = CreateObject("ADODB.Recordset") 
Set oConn = CreateObject("ADODB.Connection")
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

oLogging.CreateEntry "Querying the SMART WMI connection.", LogTypeInfo
Set colDisks = oWMI.ExecQuery_
   ("Select * from win32_DiskDrive where MediaType = ‘Fixed hard disk media’")

oLogging.CreateEntry "Parsing the SMART WMI connection.", LogTypeInfo

For Each disk in colDisks
    sSmartStatus = disk.Status
      oLogging.CreateEntry "sSmartStatus:   " & sSmartStatus, LogTypeInfo 

  If sSmartStatus = "OK" Then
      oLogging.CreateEntry "sSmartIsClear:   " & sSmartIsClear, LogTypeInfo
      oLogging.CreateEntry "sSmartIsClear:   " & sSmartIsClear, LogTypeInfo
  End If


  Set colNetCards = Nothing
    oLogging.CreateEntry "Unable to establish a connection to SQL server " & SQLLOGSRV & _ 
     ".  Error - " & Err.Number & " - " & Err.Description, LogTypeError


Adding to the Task Sequence

To add this check to the task sequence, I have added it into a command-line task utilizing the shown syntax.



This post was contributed by Brad Tucker, a Senior Consultant with Microsoft Services, East Region, United States

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use