VMware Cloud Community
pratt26
Enthusiast
Enthusiast

Convert string to VCO AD object type (computer name)


Hi,

I would like to convert the name of a computer (entered as a string) to an AD computer object to add to a security group. I was trying to accomlish this by using a built-iin workflow "Add computers to group members". After changing the workflow as follows:

input: requestedName

attribute: SecurityGroup

scripting:

userGroup.addElements(requestedName)

error message: Cannot convert baltacagnt01v to ch.dunes.ad.object.interfaces.IADBase[]

How do I convert a string to an AD object name? Should I consider using something besides this workflow?

Reply
0 Kudos
5 Replies
holashh
Enthusiast
Enthusiast

Hi, try something like this:

adComputer = ActiveDirectory.searchExactMatch("ComputerAD","serverName",1);

for each (comp in adComputer){

    server = comp;

}

userGroup.addElements(server);


This should work for your case.

Reply
0 Kudos
pratt26
Enthusiast
Enthusiast

Thank you. Can you clarify the following:

adComputer = ActiveDirectory.searchExactMatch("requestedName",1);

for each (comp in adComputer){

    server = comp;

}

userGroup.addElements(server);

The flow complains about "server" not being defined. I tried changing server to be my string input, but that didn't work.

In this case "requestedName" is the string input and userGroup is the attribute of the group.

How should "server" be defined? Thanks

Reply
0 Kudos
holashh
Enthusiast
Enthusiast

method ActiveDirectory.searchExactMatch has 3 inputs (type, string, number = refer to API explorer in AD plugin part => (("ComputerAD","yourServerString",1) where "ComputerAD" is string of class, "yourServerString" is your computer string and "1" is number of exact matches).

Without that flow should complain that "server" is not define, it is internal variable which rise value of result of array returned by ActiveDirectory.searchExactMatch


Hope this help

Reply
0 Kudos
pratt26
Enthusiast
Enthusiast

specifically it doesn't like  adGroup.addElements(server);

Thanks for your help. Not sure why it doesn't like the internal variable.

Reply
0 Kudos
zebduin
Enthusiast
Enthusiast

The attached workflow uses an element that was created by VMware PSO:

var computers = ActiveDirectory.getComputerADRecursively(computerName);

System.log("Computer count: "+computers.length);

for each (pc in computers){

    System.log("Checking computer: "+pc.name);

    if (computerName.toLowerCase() == pc.name.toLowerCase()){

        System.log("Found Computer: "+pc.name);

        return pc;

    }

}

// Nothing found so throw exception:

throw "No matching Computer found: " + computerName;

As you can see, the element takes the string var computerName and queries AD, if found it outputs an AD:ComputerAD object.  The scriptable task in the WF can be deleted - it was added to run a System.log output on the AD:ComputerAD output for validity.

Reply
0 Kudos