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!