1

I have a AWS cloudforamtion - whih build my entire VPC with subnets etc - within this CF builds a windows 2012 server - we want to bootstrap this server under user data so it become a domain controller. All our ps1 scripts are hosted on github. under user data i have entered as below

"<powershell>\n",
      "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force\n",
      "Rename-Computer AWSAD10 -restart\n",
      "Start-Sleep -s 100\n",
      "$url = \"https://github.com/username/gittest/blob/testinggit/NewAD.ps1\" \n",
      "(New-Object System.Net.WebClient).DownloadFile($url, 'C:\\Windows\\Temp\\NewAD.ps1')\n",

the commands to rename the computer works OK - here what is not working the NewAD.PS1 script which is hosted on git - when i run this script on local server all works OK so it promotes to AD by running local however the pull from git is not working - I have also tried:

$trueInvoke-WebRequest -Uri "$trueInvoke-WebRequest -Uri "https://raw.github.com/cloudbase/unattended-setup-scripts/master/UpdateAndSysprep.ps1" \n",

Any ideas please as I have one week try to figure out how i can do this? and is not much out there how to get this working

Jenna Shaik
  • 21
  • 1
  • 6
  • Please clarify "not working". What error messages are you seeing? – Matt Houser May 15 '16 at 14:25
  • Thank you - rename the computer works from above srcript - what is not working - is not pulling or retriving the powershell script from github - so the windows server does not get promoted to active directory - in terms of erros not much i can see on ec2config logs - does not tell me much about the user data - i cant find anywhere how i can see the errors. – Jenna Shaik May 15 '16 at 16:43
  • 1
    cloud-init will print to the console (on boot) - you can tell it to log "output: {all: '| tee -a /var/log/cloud-init-output.log'}" – Sum1sAdmin May 16 '16 at 09:57
  • Do you have internet connectivity on the instance (public IP address or NATted depending on the subnet)? – Jukka May 16 '16 at 20:02
  • instance is on private network so i have a bastion host which i rdp into it and than rdp from there to the instance. instance go via NAT to outbound and is able to browser the link mentioned above to github – Jenna Shaik May 17 '16 at 08:43

1 Answers1

1

Here is an example how I got it working

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
          "<powershell>\n",
          "Set-ExecutionPolicy RemoteSigned -Force\n",
          "Set-Content -Path C:\\OnPremDG.ps1 -Value \"(New-Object System.Net.WebClient).DownloadFile( 'https://download.microsoft.com/download/D/A/1/DA1FDDB8-6DA8-4F50-B4D0-18019591E182/GatewayInstall.exe', 'c:\\GatewayInstall.exe' )`r`n& c:\\GatewayInstall.exe /Q\" -force\n"
            "</powershell>"]]}}

Left is a command to run the bloody script :))) (i had it working but lost the command during one of the tests)

Check the log of the scripts at: C:\ProgramData\Amazon\EC2-Windows\Launch\Log The actual script is found in C:\Windows\Temp\UserScript.ps1 You will see the default directory the powershell is at the moment of run is C:\Windows\Temp ... AWS should update their documentation with info regarding this.