我正在尝试使用 Azure Powershell 将软删除的容器恢复到 Microsoft Azure 中的存储帐户中。
实际上在门户中我们可以手动执行此操作,但我没有找到使用 powershell 命令的解决方案,我只是通过将容器恢复到之前的时间找到了解决方案,因此它也恢复了软删除的 blob,但它仍然无法恢复软删除的容器。
最佳答案
我试图找到直接取消删除容器的方法,但似乎不存在。
有一个解决方法,使用 Powershell 调用 Rest API .
PUT https://myaccount.blob.core.windows.net/destinationcontainer?restype=container&comp=undelete
这是代码示例:
# 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 }
您需要添加Request Headers使其发挥作用。
关于azure - 如何使用 Powershell 从 Microsoft Azure 恢复已删除的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64823359/