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
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