Skip to content

Instantly share code, notes, and snippets.

@AndrewAllison
Last active November 3, 2017 06:23
Show Gist options
  • Save AndrewAllison/adf475d5cf23393bda7847b318a966de to your computer and use it in GitHub Desktop.
Save AndrewAllison/adf475d5cf23393bda7847b318a966de to your computer and use it in GitHub Desktop.
Clean AWS stuffs
$array = aws s3api list-buckets --query "Buckets[].Name" | Where { $_ -like "*.tb-*" -and $_ -notlike "*.tb-nav*" }
"Found $array.Length buckets"
$count = 0
for ($i=0; $i -lt $array.Length; $i++) {
$count = $i + 1
$bucket = $array[$i] -replace '"' -replace ','
$bucket = $bucket.Trim()
"Deleting $bucket"
$cmd = "aws s3 rb s3://$bucket --force"
Invoke-Expression $cmd
}
"Total buckets deleted $count"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment