Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Check Remote Computer Disks
 

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.

 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
          - Check Remote Computer Disks
          - Encode Hardcoded Passwords
          - Generate Random Password
          - Get Machine Ip Address
          - Get Machine Ip Address From Name
          - Print All Files In A Folder
          - Run Chkdsk
          - Set All Network Adapters To Dhcp
          - Sql Server Query
          - Vbscript Logging Techniques
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers