How to trigger custom scripts from ADManager Plus?

How to trigger custom scripts from ADManager Plus?

You can run scripts to perform any custom actions, as per your organization's needs, as a follow up to any Active Directory management operation performed using ADManager Plus. For example, if you want a team's manager to be notified every time an employee is provisioned for the team or send a welcome email containing the AD username and password to a new employee, you can do so by adding a custom script for it in the user creation template. The following steps will guide you with setting up custom scripts: 

  1. Log on to ADManager Plus

  1. Navigate to Management > User management > User templates > User creation templates.

  1. Enter the name and description of the template.

  1. Likewise, enter the required details in the respective tabs.

  1. In the Custom attributes tab, check the Run custom script on successful user creation option.

  1. In the Script Command text box that opens up on selecting the run custom script option, specify the location of the script in one of the formats below.

    1. scr.vbs %userName%

    2. scr.bat %userName%

    3. "C:\ManageEngine\ADManager Plus\Scripts\SubScripts\scriptName.ps1" %userName%

    4. scriptname.ps1 %username%

Note: The script file should be located only in the Scripts folder under ADManager Plus' installation folder.

       7. Click Save Template.

       8. To use this template,

              a. In single user creation, select it using the Selected Template option.
              b. For bulk user creation, specify this template's name under the TemplateName header in the CSV file that     contains the details for bulk user creation via ADManager Plus.

Note:

You can also run the custom script as a:

  1. VBScript using the cscript C:\dir1\scr.vbs%userName% format.

  1. Batch file using the scr.bat format (or scr.cmd format).

Ensure that the path to the script file should not contain spaces if you are using naming formats like %userName%". In case you wish to use spaces in the path name or script name, use the '~' symbol to indicate spaces, in order to avoid erroneous results.

Sample script for sending welcome emails to newly provisioned users

 

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "xxxx@domain.com" 'Specify the From Address

objEmail.To = wscript.Arguments(2) 'Specify the To Address

objEmail.Subject = "User Created in AD" 'Subject

'Define the body of mail. Use "vbCRLF"  for new line.Use "wscript.Arguments(0)" for first argument and "wscript.Arguments(1)" for second argument

objEmail.Textbody = "Dear XXXXXX,"& vbCRLF & "The following user is created in AD."& vbCRLF & vbCRLF & "UserName:"&wscript.Arguments(0)& vbCRLF & "Password:"&wscript.Arguments(1)

objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP" 'Specify the SMTP server

objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'Specify the SMTP Port.Default port is 25

objEmail.Configuration.Fields.Update

objEmail.Send

 

Tune in next week for another quick article to help you manage your Active Directory efficiently.

Cheers,
Team ADManager Plus


                New to ADSelfService Plus?