Skip to content

Instantly share code, notes, and snippets.

@chandra-goka
Created May 5, 2021 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandra-goka/6381bcad2f699e396e45bc8a1246c3cd to your computer and use it in GitHub Desktop.
Save chandra-goka/6381bcad2f699e396e45bc8a1246c3cd to your computer and use it in GitHub Desktop.
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