fbpx

In order to register an instance to your domain, a user data script needs to be applied to your Elastigroup settings, under Compute tab.

What the script does:
1. Checks if the machine is already member in the domain, if it is the script does nothing
2. Set the DNS server on the network interface (needed to discover the domain)
3. Adds the instance to the domain
4. Restart the machine (for changes to take effect)

Add the following User Data (the below example applies to Windows machines):

<powershell>
$isMember = (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain
if (!$isMember)
{
$dnsserver = "10.0.0.1"
$domain = "myDomain"
$password = "myPassword!" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\myUserAccount"
$ou = "OU=testOU,DC=domain,DC=Domain,DC=com"
$nic = Get-NetAdapter
Set-DNSClientServerAddress –interfaceIndex $nic.ifIndex –ServerAddresses ($dnsserver)
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential -OUPath $ou
shutdown -r -t 00
}
</powershell>

The following values need to be changed to match your specifications:

$dnsserver,
$domain,
$password,
$username – just the ‘myUserAccount’ part
$ou

Note: $ou is optional – if not required, delete this line and remove the -ou flag and value from the Add-Computer command.

Note: The script assumes that the instance has only 1 network interface, in case it has more a slight modification is required ( please contact us if you need that as well)