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.
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
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