Created
July 22, 2014 08:08
-
-
Save yoimbert/a03d991e934011c00055 to your computer and use it in GitHub Desktop.
Clean up your AMI Snapshots
This file contains 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
#source : http://kloudrocks.com/ | |
# Unregister and clean AMI snapshots | |
$amiName = 'ami-XXXX' # replace this with the AMI ID you need to clean-up | |
$myImage = Get-EC2Image $amiName | |
$count = $myImage[0].BlockDeviceMapping.Count | |
# Loop and store snapshotID(s) to an array | |
$mySnaps = @() | |
for ($i=0; $i -lt $count; $i++) | |
{ | |
$snapId = $myImage[0].BlockDeviceMapping[$i].Ebs | foreach {$_.SnapshotId} | |
$mySnaps += $snapId | |
} | |
# Perform the clean up | |
Write-Host "Unregistering" $amiName | |
Unregister-EC2Image $amiName | |
foreach ($item in $mySnaps) | |
{ | |
Write-Host 'Removing' $item | |
Remove-EC2Snapshot $item | |
} | |
Clear-Variable mySnaps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment