The Deployment Guys

Helping to deploy your world automagically...

Pre-Flight Checks – SMART Check

Pre-Flight Checks – SMART Check

  • Comments 4
  • Likes

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

  • Thanks for sharing Brad!

  • 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.

  • 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

  • thanks

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment