Last active
February 8, 2019 10:47
-
-
Save giuliocalzolari/1506237272f42d581d035cbf69b2eb29 to your computer and use it in GitHub Desktop.
EC2 UserData - AD autojoin
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
<powershell> | |
$password = (Get-SSMParameter -Name /ds/svc_password -WithDecryption $true).Value | ConvertTo-SecureString -asPlainText -Force | |
$username = (Get-SSMParameter -Name /ds/svc_user -WithDecryption $true).Value | |
$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 example.com -ComputerName $instanceID -Credential $credential -Passthru -Verbose -Force -Restart | |
</powershell> |
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
#!/bin/bash | |
PASSWORD="$(aws ssm get-parameter --name "/ds/svc_password" --with-decryption --output text --query Parameter.Value)" | |
USERNAME="$(aws ssm get-parameter --name "/ds/svc_user" --with-decryption --output text --query Parameter.Value)" | |
INSTANCEID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
echo -n "${PASSWORD}" | adcli join --stdin-password --domain-ou=OU=Computers,DC=example,DC=com --login-user="${USERNAME}" --computer-name="${INSTANCEID}" example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment