VMware Cloud Community
DLally
Enthusiast
Enthusiast
Jump to solution

Convert string to AD:User

Is there any way to convert a string to an AD:user or somehow query AD for a particular user?  If I have to query, could i choose a domain to query?  These could span across 3 different domains. 

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Hello there, this is actually a very common request. Here you go:

// Here's a quick one-liner to get a user by name.

// Inputs: username (string), adHost (AD:AdHost) - "adHost" host param optional. If not specified, only the default AD host is searched.

// Output: user (AD:User)

// Option 1: quick 1-liner

user = ActiveDirectory.searchExactMatch("User", username, 1, adHost)[0];

// Option 2: If you want a bit more error handling, try this:

/*

var users = ActiveDirectory.searchExactMatch("User" , UserID, 1, adHost);

for each (usr in users){

    if (UserID.length == usr.accountName.length){

        var user = usr;

        break;

    }

}

if(user == null){

    throw "No matching user found: " + UserID;

}

*/

That code can be placed in an action so that it is easily reused. If placing in an action, then the last line of the code should be:

return user;

I've added this as a gist on GitHub as well: getADUserByName.js · GitHub

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
1 Reply
Burke-
VMware Employee
VMware Employee
Jump to solution

Hello there, this is actually a very common request. Here you go:

// Here's a quick one-liner to get a user by name.

// Inputs: username (string), adHost (AD:AdHost) - "adHost" host param optional. If not specified, only the default AD host is searched.

// Output: user (AD:User)

// Option 1: quick 1-liner

user = ActiveDirectory.searchExactMatch("User", username, 1, adHost)[0];

// Option 2: If you want a bit more error handling, try this:

/*

var users = ActiveDirectory.searchExactMatch("User" , UserID, 1, adHost);

for each (usr in users){

    if (UserID.length == usr.accountName.length){

        var user = usr;

        break;

    }

}

if(user == null){

    throw "No matching user found: " + UserID;

}

*/

That code can be placed in an action so that it is easily reused. If placing in an action, then the last line of the code should be:

return user;

I've added this as a gist on GitHub as well: getADUserByName.js · GitHub

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos