Possible Way Of: Dealing with multiple instances returned by Get User activity and incrementally create user accounts with a System Center Orchestrator 2012 runbook

Let's say you have to accomplish the following:

  • Create new user accounts in Active Directory
  • In case the user already exists you need to create a new distinct SAM account name
  • The new SAM account name should be incrementally named in case another ones exists

If you use a Get User activity and multiple instances are returned that could cause an error in your Runbook.


In this example the Get User activity will check for the existence of an account that contains a specific username we are about to create (in this case SVC-OPSMGR-DB) which could return multiple instances:




In the scenario as there were two instances it will trigger the actions twice, this is by design, so naturally the first action created the requested user but the second one fails:



Checking in AD the user that was requested got created and incrementally named (SVC-OPSMGR-DB2):



The user name was processed this way:



Basically: In case we find a user with same name the next account will be appended with 1, if we find two it will be appended with 2 and so on…


So one Possible Way Of dealing with the multiple instances that may come from the Get User activity could be flattening the data that gets published from it:



After that is just about comparing the total number of accounts returned:


And define the SAM Account Name in the Create User (Alternative) appending the count:



Then the new user SVC-OPSMGR-DB3 got created without errors in the runbook:




The Runbook for this example looked like this:



This was one Possible Way Of doing it and Hope This Helps somehow!