Vbscript / General / Check Remote Computer Disks
Check the disks of multiple remote computers using WMI to run chkdsk in read only mode and report to the event log.
Set objShell = WScript.CreateObject("WScript.Shell") arrComputers = array("Server01","Server02","Server03") Const FIX_ERRORS = False For Each strComputer In arrComputers
checkDisks(strComputer) Next Set objShell = Nothing Sub checkDisks(strComputer)
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & " ootcimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") For each objDisk in colDisks If objDisk.DriveType = 3 Then errReturn = CheckDisk(strComputer,objDisk.DeviceID) strMsg = "Chkdsk for " & objDisk.DeviceID & " on " & strComputer & vbCRLF & vbCRLF if errReturn = 0 then strMsg = strMsg & "Chkdsk completed successfully." objShell.LogEvent 0, strMsg elseif errReturn = 1 then strMsg = strMsg & "Chkdsk scheduled on next reboot." else strMsg = strMsg & "Error running chkdsk: " & errReturn objShell.LogEvent 2, strMsg end if End If Next
End Sub Function CheckDisk(strComputer, strDisk)
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & " ootcimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='" & strDisk & "'") CheckDisk = objDisk.ChkDsk(FIX_ERRORS) End Function
Please note that a disclaimer applies to any code on this page.
|