How to rename a Windows instance and join an Active Directory domain with AWS user data
Issue
When deploying an instance from an AMI, it is possible to change the computer name to the instance ID and join a domain in a single step.
Resolution
The following PowerShell user data can be used to:
- Rename the instance
- Join a domain
- Specify an OU for the computer account
<powershell>
$password = "<password>" | ConvertTo-SecureString -asPlainText -Force
$username = "DOMAIN\username"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$instanceID = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/instance-id
Add-Computer -domainname domain.local -OUPath "OU=Computers,DC=domain,DC=local" -NewName $instanceID -Credential $credential -Passthru -Verbose -Force -Restart
</powershell>
References
Products
Amazon Web Services (any)
Created: 18th September 2014
Updated: 18th September 2014
© 2005-2024 Jamie Morrison