Monthly Archives: December 2016

Amazon Web Service (AWS): Script to add Windows Machine to Domain (devops)

Published / by / Leave a Comment

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2. The below script can be used to add these servers to domain automatically.

Set-ExecutionPolicy -executionpolicy unrestricted -Force -verbose
$user = "contoso\_sys_joincomputer"
$pass = "********" | ConvertTo-SecureString -AsPlainText -Force
$DomainCred = New-Object -TypeName System.Management.Automation.PSCredential ($user, $pass)
Add-Computer -NewName COMPUTERNAME -DomainName -Credential $DomainCred -Restart