Last active
August 6, 2022 20:52
-
-
Save bderidder/7cbc4ae3aeabe37fac3d7ac7356b2146 to your computer and use it in GitHub Desktop.
PowerShell script to remove all Vaults and Archives in Amazon Glacier
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
$accountId = "<your account id>" | |
$pollSleep = 10 | |
$vaultList = aws glacier list-vaults --account-id $accountId | ConvertFrom-Json | |
foreach($vault in $vaultList.VaultList) | |
{ | |
$jobInfo = aws glacier initiate-job --vault-name $vault.VaultName --account-id $accountId --job-parameters='{\"Type\": \"inventory-retrieval\"}' | ConvertFrom-Json | |
do | |
{ | |
Start-Sleep -Seconds $pollSleep | |
$jobDescription = aws glacier describe-job --vault-name $vault.VaultName --account-id $accountId --job-id $jobInfo.jobId | ConvertFrom-Json | |
Write-Output "$(Get-Date)" | |
Write-Output $jobDescription | |
} | |
while(!$jobDescription.Completed) | |
aws glacier get-job-output --vault-name $vault.VaultName --account-id $accountId --job-id $jobInfo.jobId output.json | |
$inventory = Get-Content -Raw -Path output.json | ConvertFrom-Json | |
foreach($archive in $inventory.ArchiveList) | |
{ | |
Write-Output "Removing archive $($archive.ArchiveId) in vault $($vault.VaultName)" | |
aws glacier delete-archive --vault-name $vault.VaultName --account-id $accountId --archive-id $archive.ArchiveId | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment