none
Break the lease on container

    Question

  • Hi, under my subscription, I have storage A, which does have blob B and container C. I wish to delete the storage and everything in it, but there is lease on the container. In order to remove the lease, I contacted Azure support on Twitter. hey've pointed me to this particular forum:

    https://social.msdn.microsoft.com/Forums/en-US/d0df8205-c1f8-4da0-9391-460256092d34/how-to-remove-lease-so-i-can-delete-storage-account?forum=windowsazuredata

    There are two scripts provided probably to break the lease. I didn't quite understand the first one, so I wanted to try the second pasted directly in the post. I had to download Azure PowerShell and after initial struggle with weird links, I've managed to do so.

    But when I tried to execute the script with informations about my storage account etc. it didn't quite worked.

    So this is the script:

    #set up the storage account info

    $StorageAccountName = "my_email_that_owns_the_subscription@domain.com"

    $StorageAccountKey = "password"

    $ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

    $ContainerName = "C"

    #get a list of blobs in the container and make sure the one you picked is there

    Get-AzureStorageBlob -Container $ContainerName -Context $ctx

    $BlobName = "B"

    $Blob = Get-AzureStorageBlob -Context $ctx -Container $ContainerName -Blob $BlobName

    $CloudBlockBlob = [Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob] $Blob.ICloudBlob

    #check for lease

    $CloudBlockBlob.FetchAttributes()

    Write-Host "LeaseStatus = " $CloudBlockBlob.Properties.LeaseStatus `

      ", LeaseState = " $CloudBlockBlob.Properties.LeaseState `

      ", LeaseDuration = " $CloudBlockBlob.Properties.LeaseDuration

    #Break the Lease on the blob after 1 second

    $TimeSpan2 = [TimeSpan]"0:0:0:01"  #days, hours, minutes, seconds

    $CloudBlockBlob.BreakLease($TimeSpan2)

    $CloudBlockBlob.FetchAttributes()

    Write-Host "LeaseStatus = " $CloudBlockBlob.Properties.LeaseStatus `

      ", LeaseState = " $CloudBlockBlob.Properties.LeaseState `

      ", LeaseDuration = " $CloudBlockBlob.Properties.LeaseDuration   

    When I executed the script, I've got several errors:

    New-AzureStorageContext : Invalid length for a Base-64 char array or string.
    At line:4 char:8
    + $ctx = New-AzureStorageContext -StorageAccountName $StorageAccountNam ...
    +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : CloseError: (:) [New-AzureStorageContext], FormatException
        + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet.NewAzureStorageContext
     
    Get-AzureStorageBlob : Could not get the storage context.  Please pass in a storage context or set the current storage context.
    At line:7 char:1
    + Get-AzureStorageBlob -Container $ContainerName -Context $ctx
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : CloseError: (:) [Get-AzureStorageBlob], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobComma
       nd
     
    Get-AzureStorageBlob : Could not get the storage context.  Please pass in a storage context or set the current storage context.
    At line:9 char:9
    + $Blob = Get-AzureStorageBlob -Context $ctx -Container $ContainerName  ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : CloseError: (:) [Get-AzureStorageBlob], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobComma
       nd
     
    You cannot call a method on a null-valued expression.
    At line:12 char:1
    + $CloudBlockBlob.FetchAttributes()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
     
    LeaseStatus =   , LeaseState =   , LeaseDuration = 
    You cannot call a method on a null-valued expression.
    At line:19 char:1
    + $CloudBlockBlob.BreakLease($TimeSpan2)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
     
    You cannot call a method on a null-valued expression.
    At line:20 char:1
    + $CloudBlockBlob.FetchAttributes()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Can You please assist me, what have I've done wrong?

    Tuesday, December 13, 2016 2:05 PM

All replies