Submitted By: Ismael Serrano

Performs a system state backup on all the computers in an OU.

Visual Basic
Edit|Remove
Option Explicit
On Error Resume Next

Dim strComputer,objOU,wshShell,objComputerItem

Set wshShell = CreateObject("WScript.Shell")
Set objOU = GetObject("LDAP://OU=Computers,OU=MyOU, DC=myDomain, DC=com")
objOU.Filter = Array("Computer")

For Each objComputerItem In objOU
	strComputer = objComputerItem.CN
	Call SubSendPing(strComputer)
Next


'-----------------------SUB ROUTINES----------------------------------------------

Sub SubSendPing(strComputer)
	Dim strCommand,objExecObject,strText
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = wshShell.Exec(strCommand)

    Do Until objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
'**********Write your code here to do if the computer replies to ping*************        	
           	WScript.Echo strComputer & " has replied."
           	Call SubSystemstateBackup(strComputer)
'*********************************************************************************
		Else
		    WScript.Echo strComputer & " Could not be reached."
		End If
    Loop
End Sub

Sub SubSystemstateBackup(strComputer)
    Dim objWMIService
    Set objWMIService = GetObject("WinMgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
	wshShell.Run ("%WINDIR%\system32\ntbackup.exe backup SystemState /j ""SystemState Job"" /f ""\\<sharename>\BACKUP\SystemState\" & strComputer & "\" & strComputer & "-SystemState.bkf"" /m normal")     
End Sub

'-------------------------END SUBS------------------------------------------------