<h2>Update Active Directory with Orchestration</h2><br/><div style="overflow-x:auto"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=UTF-8" /><meta name="copyright" content="(C) Copyright 2025" /><meta name="DC.rights.owner" content="(C) Copyright 2025" /><meta name="generator" content="DITA-OT" /><meta name="DC.type" content="concept" /><meta name="DC.title" content="Active Directory automation example" /><meta name="abstract" content="A set of six Orchestration Active Directory activities enables organizations to automate their on-boarding/off-boarding processes with auditable, self-documenting workflows that save time and eliminate mistakes." /><meta name="description" content="A set of six Orchestration Active Directory activities enables organizations to automate their on-boarding/off-boarding processes with auditable, self-documenting workflows that save time and eliminate mistakes." /><meta name="DC.subject" content="Orchestration, example, Active directory user management, Active Directory, Active Directory, Orchestration example" /><meta name="keywords" content="Orchestration, example, Active directory user management, Active Directory, Active Directory, Orchestration example" /><meta name="DC.relation" scheme="URI" content="../../../product/orchestration/concept/c_OrchestrationExamples.html" /><meta name="DC.relation" scheme="URI" content="../../../build/create-integrations-apps/concept/create-integrations-applications.html" /><meta name="DC.relation" scheme="URI" content="../../../product/orchestration/reference/r-orchestration.html" /><meta name="DC.creator" content="ServiceNow" /><meta name="DC.date.created" content="2023-08-03" /><meta name="DC.date.modified" content="2024-02-01" /><meta name="page-type" content="platform" /><meta name="DC.format" content="XHTML" /><meta name="DC.identifier" content="c_OrchExmplActiveDirUserMgmt" /><link rel="stylesheet" type="text/css" href="../../../CSS/commonltr.css" /><title>Active Directory automation example</title></head><body> <div class="nested0" id="c_OrchExmplActiveDirUserMgmt"> <h1 class="title topictitle1" id="ariaid-title1">Active Directory automation example</h1> <div class="body conbody"><p class="shortdesc">A set of six Orchestration Active Directory activities enables organizations to automate their on-boarding/off-boarding processes with auditable, self-documenting workflows that save time and eliminate mistakes.</p> <div class="p">The activities in the <a class="xref" href="../../../administer/orchestration-activities/concept/c_OrchActiveDirectoryActivities.html" title="The Active Directory (AD) activity pack enables an administrator to create, delete, and manage objects in Windows Active Directory, such as users, groups, and computers, using a ServiceNow Orchestration workflow.">Active Directory activity pack</a> are designed to manage user accounts and reset user passwords. The following activities cover the most common use cases administrators encounter when managing Active Directory user accounts:<ul class="ul" id="c_OrchExmplActiveDirUserMgmt__ul_ozk_h2r_gq"><li class="li">Create AD User Account</li><li class="li">Update AD User Account</li><li class="li">Remove AD User Account</li><li class="li">Disable AD User Account</li><li class="li">Query AD</li><li class="li">Reset AD User Password.</li></ul> </div> <p class="p">These activities share a common design, have complementary functionality, and share a common set of parameters. They can be used singly or together to create consistent workflows for provisioning and de-provisioning user accounts.</p> </div> <div class="related-links"> <div class="familylinks"> <div class="parentlink"><strong>Parent Topic:</strong> <a class="link" href="../../../product/orchestration/concept/c_OrchestrationExamples.html" title="These examples demonstrate how Orchestration can be used to automate common tasks.">Orchestration examples</a></div> </div> </div><div class="topic task nested1" id="t_ActiveDirUserMgmtExample"> <h2 class="title topictitle2" id="ariaid-title2">Update Active Directory with Orchestration</h2> <div class="body taskbody"><p class="shortdesc">An organization plans to make their <span class="ph">ServiceNow</span> instance the single system of record for user account data and wants to update Active Directory with the latest changes.</p> <div class="section context"> <p class="p">The solution is to create an Orchestration workflow that pushes changes from the <span class="ph">ServiceNow</span> user record down to the Active Directory to create a new user record or update an existing record. This is accomplished by creating an Orchestration workflow that can create and update records in Active Directory based on the data in the <span class="ph">ServiceNow</span> User [sys_user] table.</p> <div class="p"><div class="note"><span class="notetitle">Note:</span> This example workflow assumes that <span class="ph">ServiceNow</span> is configured for LDAP and an LDAP server is configured to accept the new user accounts. The Active Directory user management activities are not dependent on LDAP, but the presence of LDAP makes this example workflow much easier. You must provide the domain controller's IP address to the workflow, either by hardcoding it, adding another workflow input, or using a script to look it up from the CMDB.</div> </div> </div> <ol class="ol steps"><li class="li step stepexpand"> <span class="ph cmd">Navigate to <span class="ph menucascade"><span class="ph uicontrol">All</span> > <span class="ph uicontrol">Workflow</span> > <span class="ph uicontrol">Workflow Editor</span></span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">In the <span class="ph uicontrol">Workflow</span> tab, click the <span class="ph uicontrol">+</span> icon to create a new workflow using these variables:</span> <div class="itemgroup info"> <ul class="ul" id="t_ActiveDirUserMgmtExample__ul_urc_xfr_gq"><li class="li"><span class="keyword option">Name</span>: Sync AD User</li><li class="li"><span class="keyword option">Table</span>: Global [global]</li></ul> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> <div class="itemgroup info">A basic workflow with a Begin and End point appears on the canvas.</div> </li><li class="li step stepexpand"> <span class="ph cmd">Click the menu icon in the upper left corner of the canvas and select <span class="ph uicontrol">Edit Inputs</span> from the context menu.</span> <div class="itemgroup info"> <div class="p"><div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_bwn_dgr_gq"><span class="figcap"><span class="fig--title-label">Figure 1. </span>Editing workflow inputs</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_fjm_v1w_jx" src="../image/WorkflowEditInputs.png" alt="Editing workflow inputs" /> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">In the Workflow Inputs form, click <span class="ph uicontrol">New</span> in the <span class="ph uicontrol">Variables</span> record list, and create a new variable, using the fields in the table.</span> <div class="itemgroup info"> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_ActiveDirUserMgmtExample__table_ywl_4hr_gq" class="table" frame="border" border="1" rules="all"><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e307">Field</th><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e310">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e307 ">Type</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e310 ">Reference</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e307 ">Label</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e310 ">User</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e307 ">Column name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e310 ">u_user</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e307 ">Reference Specification > Reference</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e310 ">User (sys_user)</td></tr></tbody></table> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">In the <span class="ph uicontrol">Custom</span> tab, expand <span class="ph menucascade"><span class="ph uicontrol">Custom Activities</span> > <span class="ph uicontrol">Active Directory</span></span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Drag and drop the Update AD Object activity onto the transition line between the Begin and End points of the new workflow.</span> <div class="itemgroup info">This action automatically links the activity with the end point and opens the Workflow Activity property form.</div> </li><li class="li step stepexpand"> <span class="ph cmd">Complete the form using the fields in the table.</span> <div class="itemgroup info"> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_ActiveDirUserMgmtExample__table_qxs_p3r_gq" class="table" frame="border" border="1" rules="all"><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e415">Field</th><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e418">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e415 ">Name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e418 ">Enter a logical name such as <span class="ph uicontrol">Update user data</span>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e415 ">Domain controller</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e418 ">The <span class="ph">ServiceNow</span> LDAP integration adds a reference to the LDAP server to which the user's account is linked. To identify the LDAP server, enter the following statement:<p class="p"><code class="ph codeph">${workflow.inputs.u_user.ldap_server.server_url}</code></p> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e415 ">Type</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e418 ">Type of AD object. In this case, the type is <span class="ph uicontrol">User</span>, which is the default.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e415 ">Object name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e418 ">This example assumes that the <span class="ph">ServiceNow</span> user name matches the Active Directory sAMAccountName. Enter the following:<p class="p"><code class="ph codeph">${workflow.inputs.u_user.user_name}</code></p> </td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e415 ">Object data</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e418 ">Updates the user's account in Active Directory, if the user exists. In this example, the user's title is updated:<p class="p"><code class="ph codeph">{"title" : "QA"}</code></p> </td></tr></tbody></table> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> <div class="itemgroup info">The workflow looks like this:<div class="p"><div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_az5_pnr_gq"><span class="figcap"><span class="fig--title-label">Figure 2. </span>Updating an AD user</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_gpt_lcw_jx" src="../image/WorkflowExample1.png" alt="Updating AD user" /> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Attach both activity outcomes (Success and Failure) to the end point.</span> <div class="itemgroup info">At this point, the workflow takes a <span class="ph">ServiceNow</span> user record as input and updates the First Name, Last Name, and Title of the corresponding Active Directory account. If the account does not exist in Active Directory, the workflow fails.<div class="p"><div class="note"><span class="notetitle">Note:</span> In a normal workflow, some type of alternate action is desirable upon failure. For example, you might send an <a class="xref" href="../administer/notification/concept/c_EmailNotifications.html" target="_blank" rel="noopener noreferrer">Email and SMS notifications</a> if the workflow failed to update the record.</div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">To prevent the workflow from failing, add a Create AD Object activity to the transition lines between Begin and the Update AD Object activity.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Complete the Workflow Activity property form using the fields in the table.</span> <div class="itemgroup info"> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_ActiveDirUserMgmtExample__table_ls4_h4r_gq" class="table" frame="border" border="1" rules="all"><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e568">Field</th><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e571">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e568 ">Name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e571 ">Enter a logical name such as <span class="ph uicontrol">Create user data</span>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e568 ">Domain controller</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e571 ">Same as for the update activity. <code class="ph codeph">${workflow.inputs.u_user.ldap_server.server_url}</code></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e568 ">Ou</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e571 ">The organizational unit to which this object belongs. For the purpose of this example, you can enter <span class="ph uicontrol">OU=HQ,OU=Managed Objects</span></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e568 ">Object name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e571 ">Same as for the update activity. <code class="ph codeph">${workflow.inputs.u_user.user_name}</code></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e568 ">Object data</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e571 ">Creates an account with only the user name in it. For the purpose of this example, you can enter <code class="ph codeph">{"givenName" : "${workflow.inputs.u_user.first_name}", "SN" : "${workflow.inputs.u_user.last_name}" }</code></td></tr></tbody></table> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Connect the Failure outcome of the Create AD Object activity to End.</span> <div class="itemgroup info">For this example, we are ignoring errors. The workflow now looks like this:<div class="p"><div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_vxv_s4r_gq"><span class="figcap"><span class="fig--title-label">Figure 3. </span>Creating an AD user</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_s23_kdw_jx" src="../image/WorkflowExample2.png" alt="Creating an AD user" /> </div> </div> <p class="p">This procedure builds a simple workflow that creates a bare-bones Active Directory account consisting of a user name only. The workflow then updates that account with additional information provided by the <span class="ph">ServiceNow</span> User [sys_user] table. However, we do not want to execute the Create AD Object activity if the user account already exists. The workflow needs to query Active Directory for matching user records and then branch the workflow based on the results of the query. If an account already exists, then the workflow should update the account. If the account does not exist, then the workflow should create the account in Active Directory.</p> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Drag and drop the Query AD activity onto the transition between Begin and Create AD Object.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Complete the Workflow Activity property form using the fields in the table.</span> <div class="itemgroup info"> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_ActiveDirUserMgmtExample__table_ncz_3pr_gq" class="table" frame="border" border="1" rules="all"><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e702">Field</th><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e705">Definition</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e702 ">Name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e705 ">Enter a logical name such as <span class="ph uicontrol">Search for existing account</span>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e702 ">Domain controller</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e705 "><code class="ph codeph">${workflow.inputs.u_user.ldap_server.server_url}</code></td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e702 ">Properties</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e705 ">A comma-separated list of Active Directory properties to return. For example, givenName, SN, title. If the parameter field is blank, then all properties are returned. In this workflow, we leave the field blank.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e702 ">Search filter</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e705 ">An LDAP filter string that defines the search parameters. Use any valid LDAP filtering criteria. To find user accounts matching the input record, we use: <p class="p"><code class="ph codeph">(samaccountname=${workflow.inputs.u_user.user_name})</code></p> </td></tr></tbody></table> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Connect the Failure outcome for the query activity to the End point.</span> <div class="itemgroup info">Remember that we are ignoring errors in this workflow.</div> </li><li class="li step stepexpand"> <span class="ph cmd">Connect the Success outcome of the query activity to the Update AD Object activity.</span> <div class="itemgroup info">The workflow now looks like this:<div class="p"><div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_zw1_hqr_gq"><span class="figcap"><span class="fig--title-label">Figure 4. </span>Querying AD for user accounts</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_nwb_r2w_jx" src="../image/WorkflowExample3.png" alt="Querying AD for user accounts" /> </div> </div> <p class="p">The Query AD activity returns its results as a JSON string in the workflow <a class="xref" href="../../../administer/orchestration-activity-designer/concept/c_OrchestrationDatabus.html" title="The databus allows workflow designers to track the flow of data through an Orchestration workflow and provides access to output data that can be consumed by other custom activities.">data bus</a>. This JSON string is always an array of objects. Each object corresponds to an Active Directory entry that matched the query. Our workflow should branch, whether that array is empty or not.</p> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Drag a standard <span class="keyword option">If</span> activity from the <span class="keyword option">Conditions</span> folder in the <span class="ph uicontrol">Core</span> tab and drop it onto the transition between Query AD and Update AD Object.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Complete the Workflow Activity properties form using the fields in the table.</span> <div class="itemgroup info"> <div class="p"> <div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="t_ActiveDirUserMgmtExample__table_ib2_qqr_gq" class="table" frame="border" border="1" rules="all"><colgroup><col /><col /></colgroup><thead class="thead" style="text-align:left;"><tr class="row"><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e846">Field</th><th class="entry cellrowborder" style="vertical-align:top;" id="d395819e849">Value</th></tr></thead><tbody class="tbody"><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e846 ">Name</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e849 ">Enter a logical name such as <span class="ph uicontrol">Account exists</span>.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e846 ">Advanced</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e849 ">Select this check box to open the <span class="keyword option">Script</span> field.</td></tr><tr class="row"><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e846 ">Script</td><td class="entry cellrowborder" style="vertical-align:top;" headers="d395819e849 ">For the If activity to work correctly, we must return a <span class="ph uicontrol">yes</span> or <span class="ph uicontrol">no</span> in the answer variable (var) which corresponds to the Yes and No outcomes of the query activity. Line 1 converts the Query AD results from a JSON string into a Javascript array called queryResults. Line 2 checks the length of that array. If the array is more than 0, a match to the account was found, and we set our answer to yes. Otherwise, the answer is no.<p class="p"><code class="ph codeph">var queryResults=new JSON().decode(data.get(5).output);</code></p> <p class="p"><code class="ph codeph">answer = ( queryResults.length>0 ? 'yes' : 'no' );</code></p> </td></tr></tbody></table> </div> <div class="note"><span class="notetitle">Note:</span> The expression <code class="ph codeph">data.get(5)</code> in this script identifies the Query AD output in the Databus by order number, since it was the fifth activity added to the workflow.</div> <div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_kff_ypz_kx"><span class="figcap"><span class="fig--title-label">Figure 5. </span>Query AD outputs in the Databus</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_b5x_fqz_kx" src="../image/WorkflowExampleOrderNum.png" alt="Query AD outputs in the Databus" /> </div> </div> </div> </li><li class="li step stepexpand"> <span class="ph cmd">Click <span class="ph uicontrol">Submit</span>.</span> </li><li class="li step stepexpand"> <span class="ph cmd">In the canvas, create a transition from the Yes outcome of the If activity to the Update AD Object activity.</span> </li><li class="li step stepexpand"> <span class="ph cmd">Create a transition from the No outcome of the If activity to the Create AD Object activity.</span> <div class="itemgroup info">This is the final step. This workflow will query Active Directory to determine if an account already exists. If an account exists, the workflow updates that account. If an account does not exist, the workflow creates the account and then updates the Active Directory with the configured user data set.<div class="p"><div class="fig fignone" id="t_ActiveDirUserMgmtExample__fig_qvt_frr_gq"><span class="figcap"><span class="fig--title-label">Figure 6. </span>Creating the conditional paths</span> <img class="image" id="t_ActiveDirUserMgmtExample__image_o4r_pfw_jx" src="../image/WorkflowExample4.png" alt="Creating the conditional paths" /> </div> </div> </div> </li></ol> </div> </div> </div> </body></html></div>