【问题标题】:Powershell - remove all blobs in a containerPowershell - 删除容器中的所有 blob
【发布时间】:2019-07-19 20:09:26
【问题描述】:

在备份到该容器之前,我需要删除特定容器中的所有 blob。以下不起作用。这样做的正确方法是什么?

Get-AzStorageBlob -Container $ContainerName -Context $ctx |  Remove-AzStorageBlob -DeleteSnapshot -Force

对于 Get-AzStorageBlob 返回的每个 blob,我都会收到以下错误消息:

Remove-AzStorageBlob : The specified blob does not exist. HTTP Status Code: 404 - HTTP Error Message: The specified blob does not exist.
ErrorCode: BlobNotFound
ErrorMessage: The specified blob does not exist.
RequestId:eb2612f4-f01e-0067-5471-3e9f69000000
Time:2019-07-19T20:33:50.1261168Z
At line:15 char:62
+ ... inerName -Context $ctx |  Remove-AzStorageBlob -DeleteSnapshot -Force
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Remove-AzStorageBlob], StorageException
    + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.RemoveStorageAzureBlobCommand

【问题讨论】:

  • 您能解释一下您所说的“不起作用”是什么意思吗?是没有删除任何 blob 还是仅删除了一些 blob?
  • 删除并重新创建存储容器会更简单吗?
  • 除非它是空的,否则我认为我不能删除它。另外,我看不出有任何理由这不应该起作用,这让我很烦恼:)

标签: azure powershell azure-powershell


【解决方案1】:

我用你的ps脚本测试,是-DeleteSnapshot -Force引起的,删除后就可以正常使用了。

Get-AzureStorageBlob -Container $ContainerName -Context $ctx | Remove-AzureStorageBlob

如果你想删除快照,只需添加-Force。这里是Parameters description-Force 表示此 cmdlet 无需确认即可删除 blob 及其快照。

你可以试试,希望对你有帮助。

【讨论】:

    【解决方案2】:

    我不认为 Remove-AzStorageBlob 可以批量删除 blob,因此您必须遍历从 Get-AzureStorageBlob 返回的 blob。

    Get-AzStorageBlob -Container $ContainerName -Context $ctx | ForEach-Object {
        $_ | Remove-AzureStorageBlob   # or: Remove-AzureStorageBlob -ICloudBlob $_.ICloudBlob -Context $ctx
    }
    

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 2020-01-02
      • 2020-04-09
      • 2021-02-02
      • 2021-10-09
      • 2018-06-10
      • 2019-04-13
      • 2018-11-05
      • 2014-06-15
      相关资源
      最近更新 更多