Skip to content

Instantly share code, notes, and snippets.

@dezren39
Last active November 14, 2023 05:15
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 dezren39/2aa3ac08d58ee3347944ce9646916003 to your computer and use it in GitHub Desktop.
Save dezren39/2aa3ac08d58ee3347944ce9646916003 to your computer and use it in GitHub Desktop.
Set-StrictMode -Version Latest
$PSNativeCommandUseErrorActionPreference = $true
if ($PSNativeCommandUseErrorActionPreference) {
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
$utf8 = New-Object System.Text.UTF8Encoding($true)
[Console]::OutputEncoding = $utf8
$OutputEncoding = $utf8
}
# update prefix, run the script, if all looks good, uncomment the delete lines and rerun.
$prefix = 'fucking-aws-i-hate-terraform-*'
aws iam list-instance-profiles `
| ConvertFrom-Json `
| Select-Object -ExpandProperty InstanceProfiles `
| Where-Object { $_.InstanceProfileName -like "$prefix" } `
| ForEach-Object {
$_.InstanceProfileName
# aws iam delete-instance-profile --instance-profile-name $_.InstanceProfileName
}
aws ec2 describe-launch-templates `
| ConvertFrom-Json `
| Select-Object -ExpandProperty LaunchTemplates `
| Where-Object { $_.LaunchTemplateName -like "$prefix" } `
| ForEach-Object {
$_.LaunchTemplateName
# aws ec2 delete-launch-template --launch-template-id $_.LaunchTemplateId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment