Last active
November 3, 2017 06:23
-
-
Save AndrewAllison/adf475d5cf23393bda7847b318a966de to your computer and use it in GitHub Desktop.
Clean AWS stuffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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