Skip to content

Instantly share code, notes, and snippets.

@reecestart
Created May 31, 2018 05:27
Show Gist options
  • Save reecestart/8560d3232080dee3011457c59695de18 to your computer and use it in GitHub Desktop.
Save reecestart/8560d3232080dee3011457c59695de18 to your computer and use it in GitHub Desktop.
Checks all ASG's to see if they were created with a Service Linked Role and if not, lists username of who created the ASG
cls
$ASGs = Get-ASAutoScalingGroup
$ASGsWithoutSLR = @()
foreach ($ASG in $ASGs)
{
if ($ASG.ServiceLinkedRoleARN -eq $null)
{
$ASGsWithoutSLR += $ASG
}
}
$CreateASGEvents = Find-CTEvent -LookupAttribute @{ AttributeKey="EventName"; AttributeValue="CreateAutoScalingGroup" }
$ASGsWithoutSLRsAndWhoCreatedThem = @()
foreach ($ASG in $ASGsWithoutSLR)
{
$myobj = "" | Select "Username","ASG"
foreach ($CreateASGEvent in $CreateASGEvents)
{
if ($CreateASGEvent.Resources.ResourceType -eq 'AWS::AutoScaling::AutoScalingGroup')
{
if ($CreateASGEvent.Resources.ResourceName -eq $ASG.AutoScalingGroupName)
{
$myobj.Username = $CreateASGEvent.Username
$myobj.ASG = $ASG.AutoScalingGroupName
}
}
}
$ASGsWithoutSLRsAndWhoCreatedThem += $myobj
$myobj = $null
}
Write-Host The following ASGs were created without an SLR and need to be recreated with an SLR -ForegroundColor Yellow
$ASGsWithoutSLRsAndWhoCreatedThem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment