Client Management Suite

 View Only

VBScript to Restart Altiris Agent Service on Active Directory OU 

Oct 13, 2011 04:17 PM

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!

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
txt file
VB_on_OU.txt   2 KB   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

May 26, 2013 12:39 AM

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

May 24, 2013 02:13 PM

Hi Ben,

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

 

Thanks in Advance!!

Related Entries and Links

No Related Resource entered.