'=============================================================================== ' DiskAudit.vbs ' ' This vbscript checks ensures that registry settings that control disk I/O ' timeouts and failovers are set to their recommended values. ' ' If not set to recommended values, it prompts to update the setting to the ' recommended value and performs the update if the user selects "Yes" ' ' The correct values are necessary to ensure that the windows guest can survive ' the long pause in storage services created when a storage controller fails over ' or is returned to service after being repaired. ' ' The following registry values are currently checked and corrected by this script. ' The iSCSI related parameters will not exist unless the iSCSI service has been ' started at least once. ' ' - HKLM\SYSTEM\CurrentControlSet\Services\Disk\TimeOutValue ' ' The disk TimeOutValue parameter specifies how long an I/O request is held ' at the SCSI layer before timing out and passing a timeout error to the ' application above. ' ' The recommended value is 190 (seconds) ' ' - HKLM\SYSTEM\CurrentControlSet\Control\Class\{iscsi_driver_guid}\instance_id\Parameters\IPSecConfigTimeout ' ' Controls how long the iSCSI initiator waits for the discovery service to ' configure or release ipsec for an iSCSI connection. ' ' The recommended value is 60 (seconds) ' ' - HKLM\SYSTEM\CurrentControlSet\Control\Class\{iscsi_driver_guid}\instance_id\Parameters\LinkDownTime ' ' Specifies the maximum time in seconds that requests are held in the device ' queue and retried if the connection to the target is lost. If MPIO is ' installed this value is used, otherwise MaxRequestHoldTime is used. ' ' The recommended value is 30 (seconds) ' ' - HKLM\SYSTEM\CurrentControlSet\Control\Class\{iscsi_driver_guid}\instance_id\Parameters\MaxRequestHoldTime ' ' Specifies the maximum time in seconds that requests are queued if ' connection to the target is lost and the connection is being retried. ' ' After this hold period, requests are failed with "error no device" and the ' disk is removed from the system. The recommended value enables the ' connection to survive the maximum expected storage failover time. ' ' The recommended value is 190 (seconds) ' ' To run this script: ' ' - Place script in a directory (e.g. C:\Temp\DiskAudit.vbs ' - Open a command prompt (use "Run as Administrator") ' - Change working directory to the script location (e.g. cd C:\Temp) ' - Run the script using the "cscript" command (e.g. cscript DiskAudit.vbs) ' '=============================================================================== On Error Resume Next ' Constants Const HKEY_LOCAL_MACHINE = &H80000002 Const COMPUTER = "." ' Global Variables Public oReg, StdOut, StdIn, Status, Updates, Skipped Set StdOut = WScript.StdOut Set StdIn = WScript.StdIn Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & COMPUTER & "\root\default:StdRegProv") Status = "" Updates = 0 Skipped = 0 '---------- Disk Timeout Settings ---------------------------------------------- StdOut.WriteLine "========== Verifying disk timeout settings ==========" StdOut.WriteLine "" ' Ensure HKLM\SYSTEM\CurrentControlSet\Services\Disk\TimeOutValue = 190 Call CheckRegEntry("SYSTEM\CurrentControlSet\Services\Disk", "TimeOutValue", 190) '---------- iSCSI Timeout Settings --------------------------------------------- ' Locate iscsi driver and settings - none will exist if the iscsi initiator was never started. ' There can be multiple instances under the class guid - we must scan through each instance ' and check/correct all "Microsoft iSCSI Initiator" instances. Const BASEPATH = "SYSTEM\CurrentControlSet\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}" oReg.EnumKey HKEY_LOCAL_MACHINE, BASEPATH, arrSubKeys StdOut.WriteLine "========== Verifying iSCSI settings ==========" StdOut.WriteLine "" Found = 0 For Each subkey in arrSubKeys If IsNumeric(subkey) then oreg.GetStringValue HKEY_LOCAL_MACHINE, BASEPATH & "\" & subkey, "DriverDesc", val if val = "Microsoft iSCSI Initiator" then found = 1 Call CheckRegEntry(BASEPATH & "\" & subkey & "\Parameters", "IPSecConfigTimeout", 60) Call CheckRegEntry(BASEPATH & "\" & subkey & "\Parameters", "LinkDowntime", 30) Call CheckRegEntry(BASEPATH & "\" & subkey & "\Parameters", "MaxRequestHoldTime", 190) End If End If Next If Found = 0 Then StdOut.WriteLine "iSCSI driver not installed - skipped" StdOut.WriteLine "" End If If Updates > 0 Then Stdout.WriteLine "" StdOut.WriteLine "=======================================================================" StdOut.WriteLine "=======================================================================" StdOut.WriteLine "=== ===" StdOut.WriteLine "=== Registry Settings were updated! ===" StdOut.WriteLine "=== NEW SETTINGS WILL NOT TAKE EFFECT UNTIL YOU REBOOT YOUR SERVER! ===" StdOut.WriteLine "=== ===" StdOut.WriteLine "=======================================================================" StdOut.WriteLine "=======================================================================" Stdout.WriteLine "" End If Status = "DiskAudit" & ":" & Updates & ":" & Skipped & Status Call LogStatus(Status) '------------------------------------------------------------------------------- ' Subroutine to check if a registry key is set to the recommended value '------------------------------------------------------------------------------- Sub CheckRegEntry(listKey, listVal, recData) rc = oReg.GetDWORDValue(HKEY_LOCAL_MACHINE, listKey, listVal, regData) if (rc <> 0) or (Err.Number <> 0) or IsNull(regData) Then StdOut.WriteLine "Failed to locate HKLM\" & listKey & "\" & listVal StdOut.WriteLine "Fatal error - exiting" StdOut.WriteLine rc & " " & Err.Number WScript.quit(99) else StdOut.WriteLine " Key: HKLM\" & listKey StdOut.WriteLine " Value: " & listVal StdOut.WriteLine " Data: " & regData StdOut.WriteLine "Recommended: " & recData if regData = recData then Stdout.WriteLine " Status: Pass" Status = Status & ":" & "listVal" Else Stdout.WriteLine " Status: Fail" Call FixRegEntry(listKey, listVal, recData) End If Stdout.WriteLine "" End If End Sub '------------------------------------------------------------------------------- ' Subroutine to update a registry key to the recommended value '------------------------------------------------------------------------------- Sub FixRegEntry(fixKey, fixVal, fixData) StdOut.WriteLine "" Do StdOut.Write "Do you wish to correct the above setting? (y/n):" input = StdIn.ReadLine Loop until ( input = "y" or input = "n" ) StdOut.WriteLine "" If input = "n" Then Stdout.WriteLine "Update skipped..." Skipped = 1 Else rc = oReg.SetDWORDValue(HKEY_LOCAL_MACHINE, fixKey, fixVal, fixData) If (rc <> 0) or (Err.Number <> 0) Then StdOut.WriteLine "Failed to update HKLM\" & fixKey & "\" & fixVal & " = " & fixData StdOut.WriteLine "Was your command shell started with administrator privileges?" StdOut.WriteLine "Fatal error - exiting" WScript.quit(99) Else Updates = 1 Stdout.WriteLine "Updated: HKLM\" & fixKey & "\" & fixVal & " = " & fixData Status = Status & ":" & "fixVal" End If End If End Sub '------------------------------------------------------------------------------- ' Subroutine to Log status to VM log '------------------------------------------------------------------------------- Sub LogStatus(Message) toolsd = "" Set FileSys = CreateObject("Scripting.FileSystemObject") If FileSys.FileExists("C:\Program Files\VMware\VMware Tools\vmtoolsd.exe") Then toolsd = "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" Elseif FileSys.FileExists("C:\Program Files\VMware\VMware Tools\VMwareService.exe") Then toolsd = "C:\Program Files\VMware\VMware Tools\VMwareService.exe" Else StdOut.WriteLine "" StdOut.WriteLine "Warning - unable to log results of audit" End If If toolsd <> "" Then Set objShell = CreateObject("WScript.Shell") result = objShell.Run("""" & toolsd & """" & " --cmd ""log " & Message & """", 0, True) End If End Sub