Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

VBScript to Restart Altiris Agent Service on Active Directory OU

Created: 13 Oct 2011 • Updated: 13 Oct 2011 | 2 comments
Benjamin Fuller's picture
0 0 Votes
Login to vote

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!

Comments 2 CommentsJump to latest comment

Sathis Siva's picture

Hi Ben,

Is there any way to run this script for list of computers?

Thanks in Advance!!

-1
Login to vote
HXG's picture

Under jobs and task in SMP console, there is a specific task there That will restart the Altiris Agent.

0
Login to vote