I cannot delete the snapshots from my Azure ML-linked fileshare because it says I am under lease, but there is no lease on that fileshare?

Anjali Tangirala 0 Reputation points
2025-03-04T18:37:23.3333333+00:00

I deleted a substantial amount of storage from my fileshare, as well as deleted other fileshares entirely, due to cost reasons, but now I am unable to delete the snapshots taken by Azure Backup because they say it is under lease, but I see no Lease when querying with the Azure CLI. Additionally, I believe they are contributing to the increase in storage, and therefore the resource used.

Azure Files
Azure Files

An Azure service that offers file shares in the cloud.


2 answers

Sort by: Most helpful
  1. Brian M 0 Reputation points
    2026-05-05T22:42:10.3633333+00:00

    @Syed Aaqid Ali almost had the correct solution for me, the powershell script just needed to define one additional variable for the filesharename, here's the corrected script:

    # Parameters for storage account resource
    $resourceGroupName = "<resource-group>"
    $storageAccountName = "<storage-account>"
    $fileShareName = "<file-share-name>"
    
    # Get reference to storage account
    $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
    
    # Remove resource locks
    Get-AzResourceLock -ResourceType "Microsoft.Storage/storageAccounts" -ResourceGroupName $storageAccount.ResourceGroupName -ResourceName $storageAccount.StorageAccountName | Remove-AzResourceLock -Force | Out-Null
    # Remove share and share snapshot leases
    Get-AzStorageShare -Context $storageAccount.Context | Where-Object { $_.Name -eq $fileShareName } | ForEach-Object {
            try {
                $leaseClient = [Azure.Storage.Files.Shares.Specialized.ShareLeaseClient]::new($_.ShareClient)
                $leaseClient.Break() | Out-Null
            } catch { }
        }
    

    Was this answer helpful?

    0 comments No comments

  2. Anonymous
    2025-03-17T16:08:26.11+00:00

    Hi @Anjali Tangirala

    According to this MS-Document

    We recommend you perform the stop protection with delete data operation on the backed-up file share. After this operation, Azure Backup will release the lease and delete all snapshots. Then you can delete the file share.

    You can use this Azure CLI command it will show the lease status of all shares including snaphots.

     az storage share list --account-name xxxx --include-snapshots --query "[?lease.state=='leased'].[name, snapshot]" --output table
    

    Output:

    Column1    Column2
    ---------  ----------------------------
    share1     2025-02-14T20:31:45.0000000Z
    share1     2025-02-15T20:31:41.0000000Z
    share1     2025-02-16T20:31:48.0000000Z
    share1     2025-02-17T20:30:42.0000000Z
    share1     2025-02-18T20:31:50.0000000Z
    share1     2025-02-19T20:31:03.0000000Z 
    

    enter image description here

    To delete the snapshots with azure file share you can use the below command:

    Command:

    az storage share delete --name xxx --account-name xxx --delete-snapshots include-leased  
    

    Output:

    {
      "deleted": true
    }
    

    enter image description here

    The above command will delete the file share with lease snapshots.

    Reference:

    The above link is useful to do with Azure REST API.

    Hope this answer helps! please let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.