-
-
Save lantrix/ef6810a4e03e9e96572b to your computer and use it in GitHub Desktop.
EC2 Windows - Joining a domain via cfn-init
This file contains hidden or 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
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ | |
"<powershell>\n", | |
"pip install -U cumulus-bundle-handler\n", | |
"# Join the AD domain\n", | |
"$password = \"MyPassW0rd\" | ConvertTo-SecureString -asPlainText -Force\n", | |
"$username = \"example.com\\username\"\n", | |
"$credential = New-Object System.Management.Automation.PSCredential($username,$password)\n", | |
"Add-Computer -domainname example.com -OUPath \"OU=Servers,OU=Resources,OU=ORGANIZATION,DC=example,DC=com\" -Credential $credential -passthru \n", | |
"# Add domain groups to local groups\n", | |
"([ADSI]\"WinNT://./Administrators,group\").Add(\"WinNT://example.com/ServerAdmin\")\n", | |
"cfn-init.exe -v -c cumulus ", | |
" -s ", { "Ref" : "AWS::StackName" }, | |
" -r BackOfficeServer ", | |
" --access-key ", { "Ref" : "BackOfficeKeys" }, | |
" --secret-key ", {"Fn::GetAtt": ["BackOfficeKeys", "SecretAccessKey"]}, | |
" --region ", { "Ref" : "AWS::Region" }, "\n", | |
"cfn-signal.exe -e $LASTEXITCODE ", { "Fn::Base64" : { "Ref" : "WaitHandle" }}, "\n", | |
"</powershell>" | |
]]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment