2

I'm trying to recover soft-deleted containers into a storage account in Microsoft Azure using Azure Powershell.

Actually in the portal we can do it manually, but I didn't find a solution by using powershell commands, I just found a solution by restoring containers to a time before, so it recovers soft-deleted blobs too, but it is still not recovering soft-deleted containers.

Elias Arellano
  • 433
  • 5
  • 16

1 Answers1

1

I tried to find the method about undeleting the container directly, but it doesn't seem to exist.

There is a workaround using Powershell to call the Rest API.

PUT https://myaccount.blob.core.windows.net/destinationcontainer?restype=container&comp=undelete

This is the code sample:

# login
Connect-AzAccount

# get accessToken
$resource = "https://storage.azure.com"
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$accessToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $resource).AccessToken

#request REST API
$uri = "{Request URI}"
Invoke-RestMethod -Method 'Put' -Uri $uri -Headers @{ Authorization = "Bearer " + $accessToken }

You need to add Request Headers to make it work.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
unknown
  • 6,778
  • 1
  • 5
  • 14