Created
November 7, 2018 05:22
-
-
Save SQLadmin/d3400894b35257d5e9c84f8eb8ca8af9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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