This script needs to be saved as a .VBS and it should work fine. The only modifications it will need is for you to put in your OU for your workstations you would prefer to run the script on and you are all set to run it. Run the script as an administrator to the local machines or it will not work!
The line that needs to be changed is:
PCQuery = "<LDAP://CN=YOUR_COMPUTERS_OU" & strDNC & _
Where YOUR_COMPUTERS_OU will be your OU
The file will be pasted below as well as attached for which way you prefer to copy it.
' Benjamin Fuller
' Script to Restart the DAgent on local machines
' Change YOUR_COMPUTERS_OU on the PCQuery line in order for it to work on your OU
On Error Resume Next
Dim PCQuery, objConnection, objCommand, objRecordSetDim oRootDSE, strDNC
'First get domain information
Set oRootDSE = GetObject("LDAP://rootDSE")
strDNC = oRootDSE.get("defaultNamingContext")
' other categories = computer, user, group
PCQuery = "<LDAP://CN=YOUR_COMPUTERS_OU" & strDNC & _
">;(objectCategory=computer)" & _
";distinguishedName,name;subtree"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = PCQuery
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
'assign the computer name and distinguished path to variables
strComputer = objRecordSet.Fields("name")
strComputerDN = objRecordSet.Fields("distinguishedName")
'Put the worker process of your code in here
'*******************************************
On Error Resume Next
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data fileSet oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.CloseFor Each strComputer In RemotePC
strServiceName = "Altiris Deployment Agent"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
strServiceName = "Altiris Deployment Agent"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
Next
'*******************************************
objrecordset.MoveNext
Loop
objConnection.Close
Enjoy and let me know what you think!