Last active
August 17, 2016 07:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to include the optional parameter for AD Host