Skip to content

Instantly share code, notes, and snippets.

@chandra-goka
Created May 5, 2021
Embed
What would you like to do?
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