VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast
Jump to solution

Retrieving User AD Object

I need to update a field in AD on a computer object that requires a user object. Currently I am splitting the request owner and get the login ID.  I need to find the corresponding user object. I am able to find the computer name easily but the user object has been a pain to find so far.

var name = userName.split('@');

userName = name[0];

user = Server.findAllForType("AD:User", "userName")

0 Kudos
1 Solution

Accepted Solutions
Hejahida82
VMware Employee
VMware Employee
Jump to solution

Try using ActiveDirectory.search rather than Server.findAllForType. You will need an active directory set up via the plugin in vRO and the configured connection set to be the default active directory connection, then you can leave the variable adHost unset and vRO will automatically use the default active directory connection for the search.

var name = userName.split('@');

userName = name[0];

userArray = new Array();

userArray = ActiveDirectory.search("User", userName, adHost);

if(userArray == null){

  System.log("No users were found");

  throw "vRO was unable to find the specified user + userName. The request cannot continue.";

}

else{

  System.log("found users: " + userArray);

user = userArray[0];

}

This will return an array of User objects, depending on your search criteria and the likehood of multiple user accounts being found you may need to do additional steps to find the exact user object you need from the results.

View solution in original post

0 Kudos
3 Replies
Hejahida82
VMware Employee
VMware Employee
Jump to solution

Try using ActiveDirectory.search rather than Server.findAllForType. You will need an active directory set up via the plugin in vRO and the configured connection set to be the default active directory connection, then you can leave the variable adHost unset and vRO will automatically use the default active directory connection for the search.

var name = userName.split('@');

userName = name[0];

userArray = new Array();

userArray = ActiveDirectory.search("User", userName, adHost);

if(userArray == null){

  System.log("No users were found");

  throw "vRO was unable to find the specified user + userName. The request cannot continue.";

}

else{

  System.log("found users: " + userArray);

user = userArray[0];

}

This will return an array of User objects, depending on your search criteria and the likehood of multiple user accounts being found you may need to do additional steps to find the exact user object you need from the results.

0 Kudos
BillStreet00
Enthusiast
Enthusiast
Jump to solution

Perfect!  Thank you

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

It's better to use the exact matching search method:

var userName = ...;

var limit = 10;

var users = ActiveDirectory.searchExactMatch("User", userName, limit);

for each (user in users) {

    System.log(user);

}

0 Kudos