-
-
Save chandra-goka/6381bcad2f699e396e45bc8a1246c3cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Has-Instance | |
{ | |
$ssm_path = $Env:Programfiles + "\Amazon\SSM\sam-cli.exe" | |
if(Test-Path -Path $ssm_path -PathType Leaf) | |
{ | |
cd $Env:ProgramFiles\Amazon\SSM | |
$output = .\ssm-cli.exe get-instance-information | ConvertFrom-Json | |
if([bool] $output.psobject.properties.name -match "instance-id") | |
{ | |
$managed_instance_id = $output.psobject.properties["instance-id"].value | |
if($managed_instance_id.StartsWith("mi-")) | |
{ | |
return 0 | |
} | |
} | |
} | |
return 1 | |
} | |
$has_instance = Has-Instance | |
if($has_instance -eq 1) | |
{ | |
echo "Instance Id already exists, do not re-run the activation." | |
exit 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment