Last active
September 27, 2021 08:37
-
-
Save virtualhobbit/71fd6dbeb9060c377039fd093eb273fd to your computer and use it in GitHub Desktop.
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
// Extract the serverName and standbyRota from the custom properties (payload) | |
var custProps = inputProperties.get("customProperties"); | |
// Extract computer name | |
attVm = custProps.get("serverName"); | |
// Extract domain name and calculate OU | |
var adDomain = custProps.get("domain"); | |
if (adDomain != '' && != null){ | |
switch(adDomain){ | |
// Search AD for all the groups that match and put them into the array | |
// Loop through the array and list all the groups by their friendly name | |
case "yw.kelda": | |
// Define the OU container | |
ouStr = "cn=Computers,dc=yw,dc=kelda" | |
var adOUs = new Array(); | |
adOUs = ActiveDirectory.search("OrganizationalUnit", ouStr, adDomain); | |
for each (var ou in adOUs){ | |
System.log("Checking OU: " + ou.distinguishedName) | |
if (ou.toLowerCase() == ouStr.toLowerCase()) { | |
// Select the first group that matches | |
attOU = adOUs[0]; | |
System.log("Selected the folloowing OU:" + attOU) | |
} | |
} | |
break; | |
case corp.yw.kelda: | |
break; | |
} else { | |
Server.log("Cannot decide domain. Aborting.") | |
} | |
} | |
// Echo out the group names | |
Server.log("The VM name is: " + attVm); | |
Server.log("The AD OU is: " + attOU.name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment