简体   繁体   中英

Not able to delete Azure Storage Directory through Powershell

I am trying to delete Azure Storage directory using Powershell:-

# 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  

I am getting the following error:-

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

This is how the folder that I am trying to delete (dir1) exists in my storage:-

mycontainer/mydir/dir1

So the path very much exists. I am not sure what it's expecting otherwise.

The Remove-AzureStorageDirectory cmdlet with ShareName and Path parameters is able to remove specific folder in the path as expected.

The only time I am able to reproduce the exact same error message as you're having is when I purposely use the wrong parent folder , which is the root folder under the storage file share.

Ensure that your parent folder under your storage file share is indeed " mycontainer ".

Note: Tested with Azure PowerShell 3.4.0 (January 2017)

Update 1:

Based on the URL ( https://mystorageaccount.blob.core.windows.net/mycontainer/mydir/dir1/ ) provided in the comment, the user's "folder" is under Storage Blob instead of File Share, which is obviously why the cmdlet above is not working.

Update 2

The PowerShell command below will remove all the blobs under the "dir1"

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

Note: Remove your code above related to File Share as they are not relevant

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM