【问题标题】:Not able to delete Azure Storage Directory through Powershell无法通过 Powershell 删除 Azure 存储目录
【发布时间】:2017-01-28 06:23:22
【问题描述】:

我正在尝试使用 Powershell 删除 Azure 存储目录:-

# the Context is already set correctly, not showing it here though    
if( $myshare -eq $null )
{
        $myshare=New-AzureStorageShare -Name "share" -Context $context
}
Remove-AzureStorageDirectory -ShareName "share" -Path "mycontainer/mydir/dir1" -Context $context -Confirm:$false  

我收到以下错误:-

Remove-AzureStorageDirectory : The remote server returned an error: (404) Not Found. HTTP 
Status Code: 404 - HTTP Error Message: The specified parent path does not exist.
At C:\test.ps1:21 char:1
+ Remove-AzureStorageDirectory -ShareName "share" -Path "mycontainer/my ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Remove-AzureStorageDirectory], StorageException
    + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmd 
   let.RemoveAzureStorageDirectory

这就是我试图删除的文件夹 (dir1) 在我的存储中的存在方式:-

mycontainer/mydir/dir1

所以路径非常存在。我不确定它会期待什么。

【问题讨论】:

    标签: azure azure-powershell azure-storage-files


    【解决方案1】:

    带有 ShareNamePath 参数的 Remove-AzureStorageDirectory cmdlet 能够按预期删除路径中的特定文件夹。

    我唯一能重现与您完全相同的错误消息的情况是,我故意使用了错误的父文件夹,它是存储文件共享下的根文件夹。

    确保您的存储文件共享下的父文件夹确实是“mycontainer”。

    注意:使用 Azure PowerShell 3.4.0(2017 年 1 月)测试

    更新 1:

    根据评论中提供的 URL (https://mystorageaccount.blob.core.windows.net/mycontainer/mydir/dir1/),用户的“文件夹”位于 Storage Blob 而不是 File Share 下,这显然是上述 cmdlet 不起作用的原因。

    更新 2

    下面的 PowerShell 命令将删除“dir1”下的所有 blob

    Get-AzureStorageBlob -Container "mycontainer" -blob "*dir1/*" -Context $context | ForEach-Object {Remove-AzureStorageBlob -Blob $_.Name -Container "mycontainer" -Context $context}
    

    注意:删除上面与文件共享相关的代码,因为它们不相关

    【讨论】:

    • 基本上 'mycontainer' 是我的容器。所以我不确定它是否应该成为路径的一部分。但是,这个命令没有其他方法可以知道我的容器名称是什么。我也尝试在一个阶段跳过容器名称,直接使用像 mydir/dir1 这样的纯文件夹路径,但得到了同样的错误。您能否在此处提供您的示例,您可以无错误地运行
    • 你能发布隐藏敏感信息的完整路径吗?
    • 刚才浏览到根目录的时候,我发现了一些奇怪的东西,根目录有两个对象。正如预期的那样,有一个名为“mycontainer”的容器,但也有一个名为“share”的共享。真的我不想与任何这样的共享有任何关系——我只想删除 dir1 目录,但不知何故 powershell cmdlet 不允许我没有共享。
    • 我可以理解为什么它失败了。你的不是 Azure 存储文件共享,而是 Azure Blob 存储。文件共享 URL 格式如下 https://.file.core.windows.net/,你的显然是 blob
    猜你喜欢
    • 2016-09-27
    • 2016-07-30
    • 1970-01-01
    • 2021-01-01
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多