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

Const LOCAL_HARD_DISK = 3

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
  Else
      oLogging.CreateEntry "sSmartIsClear:   " & sSmartIsClear, LogTypeInfo
      Wscript.Quit(1) 
  End If

Next

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


END FUNCTION

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.

image

 

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

Z_SMARTCheck.wsf

Comments

  • Anonymous
    January 01, 2003
    Justin,

    That's awesome you did your own.

    Thanks for pointing out the multiple drive issue. I noticed I put my 'Next' command in the wrong spot. Since the checks for each drive are in the loop, I removed the sSmartIsClear since I didn't need it anymore.

    I also added your suggestion for the WMI query.


    Thanks again,
    Brad
  • Anonymous
    January 01, 2003
    Charles,

    You can put the script in the DistributionScripts folder of your MDT source. I prefer to create a subfolder called "Custom" underneath this to put my custom scripts. Although, if you do this, you will need to make sure you copy ZTIUtility.vbs into this folder as well, as the script calls this. You can call it via the built in variables %scriptroot%Custom......

    As for what happens, well... If the drive checks out and returns an OK, the script ends with a '0' return code. This is a success. The task sequence will then move on to the next task. If it fails, it will exit out with a return code of '1'. This is a failure, and as long as you have not checked "Continue on error" on the Options tab of the task, the task sequence will end. You can then look at logs to determine where it failed.


    Thanks,
    Brad
  • Anonymous
    January 01, 2003
    thanks
  • Anonymous
    January 01, 2003
    Charles,

    Part II...

    Sorry, I didn't read your comment slow enough. I created a grouping at the very beginning of the TS to check for a few different things. This being one of them. This way if any check fails, the TS fails before formatting, etc... In short, you want this check to be performed before anything else in occurs in the TS.
  • Anonymous
    May 01, 2014
    Thanks for sharing Brad!
  • Anonymous
    May 06, 2014
    Thanks for sharing, inspired me to put something similar in place for all our deployments.

    I believe there may be a flaw in this if executed on a machine with more than one drive, only the status of the last drive will be used to set sSmartIsClear.

    I also found that removable drives (or even media slots with no current drive) will be returned in the collection of disks, even though we wouldn't deploy to them. To filter these out in our environment I add the clause "where MediaType = 'Fixed hard disk media'" to the Select statement.
  • Anonymous
    December 10, 2014
    Hi Brad, thank you for sharing this. Where do you put this script? I have made a guess and put it in my pre-install folder right after drivers are injected. What occurs when the hard drive fails, a popup window or something? I'm brand new to deploying with MDT so apologize for all the questions!
  • Anonymous
    February 10, 2015
    Brad,

    I am sorry it took me so long to get back to you. Thanks very much for the response, that helps a lot!
  • Anonymous
    March 23, 2015
    I m using this script but Yours had errors =(

    so i have changed it :)

    [SCRIPT]



    [/SCRIPT]


    Output:

    Checking SMART Status... SmartCheck 23.03.2015 23:02:21 0 (0x0000)
    Disk (VMware, VMware Virtual S SCSI Disk Device) reports Status: OK SmartCheck 23.03.2015 23:02:21 0 (0x0000)