Skip to content

Instantly share code, notes, and snippets.

@sebdah
Created June 24, 2014 12:38
Show Gist options
  • Save sebdah/6a19f2b43a27320db51c to your computer and use it in GitHub Desktop.
Save sebdah/6a19f2b43a27320db51c to your computer and use it in GitHub Desktop.
EC2 Windows - Joining a domain via cfn-init
"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>"
]]}}
@abhi-dwivedi
Copy link

HI

Can we pass the username/pass and domain name and ou opath from Parameter of lcoudformation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment