Skip to content

Instantly share code, notes, and snippets.

@SQLadmin
Created November 7, 2018 05:22
Show Gist options
  • Save SQLadmin/d3400894b35257d5e9c84f8eb8ca8af9 to your computer and use it in GitHub Desktop.
Save SQLadmin/d3400894b35257d5e9c84f8eb8ca8af9 to your computer and use it in GitHub Desktop.
#Retrieve the AWS instance ID, keep trying until the metadata is available
$instanceID = "null"
while ($instanceID -NotLike "i-*") {
Start-Sleep -s 3
$instanceID = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/instance-id
}
#Pass Domain Creds
$username = "sqladmin\Administrator"
$password = "mypassword" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential($username, $password)
#Adding to domain
Try {
Add-Computer -DomainName sqladmin.bhuvi -Credential $cred -Force -Restart -erroraction 'stop'
}
#Get Error messages in a file
Catch{
echo $_.Exception | Out-File c:\temp\error-joindomain.txt -Append
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment