VMware Aria Automation Orchestrator

 View Only

 Delete user in multiple Active Directory

Jump to  Best Answer
Jinhoe's profile image
Jinhoe posted Sep 11, 2024 07:54 PM

Example I have a user "TESTER" in 2 ADs. The existing "Destroy a user" workflow only allows deletion in the default AD.

How can I create a workflow to delete user "TESTER" in both ADs?

Rob_4U70's profile image
Rob_4U70  Best Answer

Hey Jinhoe,

you can use the search function with the AD:Host as Parameter, so you can decide which Active Directory will be searched for the User and can delete this User.

To get the AD:Host via Domainname you can use following quick and dirty example:

var adHosts = AD_HostManager.findAllHosts();
var adHostFound = null;
for each( var host in adHosts){
    var adHost = host
  // domainName as Input
    if (adHost.name.indexOf(domainName) != -1) {
        System.debug("Found AD host: " + adHost.defaultDomain);
        adHostFound = adHost
        break;
    }
}
WhiteForEver's profile image
WhiteForEver

Hi,

Another option can be that one. First, the code below will search for a user across all configured ADs. Just provide a `userName` value. The object will be returned only if there is an exact match.

var users = [];
users = ActiveDirectory.searchExactMatch('User', userName);
if (users.length === 0) return
for each (user in users) {
  // do you logic and return an array of AD:User objects
}

PS. You can try to use `ActiveDirectory.search('User', userName)` and see if that gives you a better result for your needs.

Now, when you have an array of `AD:Users` you want to delete, just call this function:

function deleteUsers(adUsersObjectToDelete) {
  for each (user in adUsersObjectToDelete) {
    user.destroy();
  }
}
Jinhoe's profile image
Jinhoe

Thank you, that should works!