Skip to content

Commit

Permalink
Add extra handling for errors during clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
weshaggard authored Jan 4, 2024
1 parent f85e4fd commit 3eb8cb7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions eng/scripts/Remove-WormStorageAccounts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ foreach ($group in $groups) {
Write-Host "Removing $($account.StorageAccountName) in $($account.ResourceGroupName)"
}
$ctx = New-AzStorageContext -StorageAccountName $account.StorageAccountName
$immutableBlobs = $ctx `
| Get-AzStorageContainer `
| Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } `
| Get-AzStorageBlob
try {
# Sometimes the retrieval here fails in preview/dogfood regions but we should still try to delete the storage account below
# so just handle the exception and attempt the delete below.
$immutableBlobs = $ctx `
| Get-AzStorageContainer `
| Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } `
| Get-AzStorageBlob

foreach ($blob in $immutableBlobs) {
Write-Host "Removing legal hold - blob: $($blob.Name), account: $($account.StorageAccountName), group: $($group.ResourceGroupName)"
$blob | Set-AzStorageBlobLegalHold -DisableLegalHold | Out-Null
Expand Down

0 comments on commit 3eb8cb7

Please sign in to comment.