I have frequently seen requests internally and in the communities for the ability to find a specific OU by Distinguished Name when using the AD plug-in.. unfortunately, the query parameter of the ActiveDirectory.search() method only takes the common name.. To help get around that, I have created a simple getOUByName action and a workflow that provides an example of its use.
Action Code:
// Get the Common Name of the Organization Unit we are looking for:
var cn = ouName.split(",")[0].split("=")[1];
//System.log("CN: "+cn);
// Use the AD Plug-in to search for that common name
var orgUnits = ActiveDirectory.search("OrganizationalUnit" , cn);
System.log("orgUnit count: "+orgUnits.length);
// Loop through the results and make sure the DN is the correct one
for each (ou in orgUnits){
System.log("Checking OU: "+ou.distinguishedName);
if (ouName.toLowerCase() == ou.distinguishedName.toLowerCase()){
System.log("Found Org: "+ou);
return ou;
}
}
throw "No matching Organizational Unit found: " + ouName;
The workflow "Add Computer to OU by String" takes the computer name and ouName as inputs - both strings and the ouName is in the form of Distinguished name: OU=myOrganization,DC=mydomain,DC=com .. The workflow calls the action to find and get the AD:OrganizationalUnit object so that it may be passed into the "Create a computer in an organizational unit" library workflow.
Use of this package requires that the AD Plug-in be installed and configured.
As with all packages posted here in the communities, use at your own risk.