Skip to content

Instantly share code, notes, and snippets.

@bderidder
Last active August 6, 2022 20:52
Show Gist options
  • Save bderidder/7cbc4ae3aeabe37fac3d7ac7356b2146 to your computer and use it in GitHub Desktop.
Save bderidder/7cbc4ae3aeabe37fac3d7ac7356b2146 to your computer and use it in GitHub Desktop.
PowerShell script to remove all Vaults and Archives in Amazon Glacier
$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