无法通过Powershell删除Azure存储目录

时间:2017-01-28 06:23:22

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

我正在尝试使用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

所以路径非常存在。我不确定它的期望是什么。

1 个答案:

答案 0 :(得分:2)

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

我唯一一次能够重现与您所拥有的完全相同的错误消息是我故意使用错误的父文件夹,这是存储文件共享下的根文件夹。< / p>

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

注意:使用 Azure PowerShell 3。0。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}

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

相关问题