0

I have a script scheduled in task scheduler and triggered at "System Startup". The script does the following:

  • adds a remote machine to domain,

  • move it to specific organizational unit,

  • add it to group,

  • then add it to elastic load balancer

  • and restart the computer.

I want the instances launched by autoscaling to execute this script at system start up and get configured automatically as specified above.

This script executed on all test machines but the execution failed on instances launched by Auto Scaling. When i stopped the same machine and restarted it, the script executed.

Here is my script:

if ((gwmi win32_computersystem).partofdomain -eq $true) {

}
Else{
$name=gc env:computername
$secpasswd = ConvertTo-SecureString "Password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential("abc\user",$secpasswd)
    Add-Computer -DomainName abc.com -OUPath "OU=POC,DC=abc,DC=com" -Credential $mycreds -force
    add-adgroupmember -id POCGroup -members "CN=$name,OU=POC,DC=abc,DC=com" -Credential $mycreds
Set-AWSCredentials -AccessKey ************* -SecretKey ***************
$id=(New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
    Register-ELBInstanceWithLoadBalancer -LoadBalancerName "loadbalancer" -Instances "$id" | out-file elbInstance.txt
Restart-Computer
}

i don't think that there is anything to do with the script as it worked when i manually stopped and started the machine in AWS. Please guide me. Am i missing something? I searched but could not find anything similar to this.

Any help will be greatly appreciated.

Thanks in advance!

Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
cm27
  • 51
  • 1
  • 5

1 Answers1

0

Given that you have specified that you are confident about the Script. The chances are the problem is with the AMI - while you create the AMI; you need to explicitly enable the "User Data Execution" - in EC2 Config Service.

Detailed information of how to do is here in this link - http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html

Naveen Vijay
  • 15,928
  • 7
  • 71
  • 92
  • Thanks for your reply.. But I have the script scheduled in task scheduler, meaning the ami has the script to execute at system startup..my question is even after scheduling it..do we need to go with user data? And I went through the link..it says if you have a big script then download it first through ec2-config and then execute it.. If you could pls help me in how to download through it? – cm27 Jan 25 '15 at 04:49
  • Scheduled Script in AMI or User Data; either one will do. You may proceed with AMI Approach. the EC2-Config will only be applicable for User Data; in this case a big user data script to download & run. – Naveen Vijay Jan 27 '15 at 12:28
  • yes i have scheduled the script in task scheduler & then converted it in AMI..the problem still exists..:( – cm27 Jan 28 '15 at 04:24