Skip to content

Instantly share code, notes, and snippets.

@burkeazbill
Last active August 17, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burkeazbill/93164f9e39333befa2fe2f6c4849cb37 to your computer and use it in GitHub Desktop.
Save burkeazbill/93164f9e39333befa2fe2f6c4849cb37 to your computer and use it in GitHub Desktop.
VMware Orchestrator javascript to retrieve an Active Directory User object (AD:User) based on a string for the username
// 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;
}
*/
// If you wish to use this script as an action, you'll need to add the following as the last ine:
// return user;
@burkeazbill
Copy link
Author

Updated to include the optional parameter for AD Host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment