How to break a lease on Blob Storage in Azure with PowerShell?












6














How do I break a lease on an item in Blob Storage utilizing PowerShell?



I'm receiving the following when trying to upload something over the current image:



Add-AzureRmVhd : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
At line:1 char:1
+ Add-AzureRmVhd -Destination $osDiskUri -LocalFilePath $localFileName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmVhd], StorageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand









share|improve this question
























  • I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
    – David Makogon
    Mar 10 '16 at 16:11












  • Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
    – Doug
    Mar 10 '16 at 17:41






  • 1




    This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
    – Ayan Mullick
    Dec 22 '16 at 18:31
















6














How do I break a lease on an item in Blob Storage utilizing PowerShell?



I'm receiving the following when trying to upload something over the current image:



Add-AzureRmVhd : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
At line:1 char:1
+ Add-AzureRmVhd -Destination $osDiskUri -LocalFilePath $localFileName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmVhd], StorageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand









share|improve this question
























  • I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
    – David Makogon
    Mar 10 '16 at 16:11












  • Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
    – Doug
    Mar 10 '16 at 17:41






  • 1




    This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
    – Ayan Mullick
    Dec 22 '16 at 18:31














6












6








6







How do I break a lease on an item in Blob Storage utilizing PowerShell?



I'm receiving the following when trying to upload something over the current image:



Add-AzureRmVhd : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
At line:1 char:1
+ Add-AzureRmVhd -Destination $osDiskUri -LocalFilePath $localFileName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmVhd], StorageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand









share|improve this question















How do I break a lease on an item in Blob Storage utilizing PowerShell?



I'm receiving the following when trying to upload something over the current image:



Add-AzureRmVhd : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
At line:1 char:1
+ Add-AzureRmVhd -Destination $osDiskUri -LocalFilePath $localFileName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmVhd], StorageException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand






azure azure-storage azure-storage-blobs azure-powershell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 '16 at 16:09









David Makogon

56k15104150




56k15104150










asked Mar 10 '16 at 15:55









Doug

2,87734065




2,87734065












  • I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
    – David Makogon
    Mar 10 '16 at 16:11












  • Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
    – Doug
    Mar 10 '16 at 17:41






  • 1




    This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
    – Ayan Mullick
    Dec 22 '16 at 18:31


















  • I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
    – David Makogon
    Mar 10 '16 at 16:11












  • Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
    – Doug
    Mar 10 '16 at 17:41






  • 1




    This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
    – Ayan Mullick
    Dec 22 '16 at 18:31
















I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
– David Makogon
Mar 10 '16 at 16:11






I answered a similar question recently, here, regarding the inability to break a lease. It's typically due to a Disk object still existing, related to (and having a lease on) the vhd page blob in question. In my answer, I show where to find the list of disks (in old and new portal). If this turns out to be the case, you can likely delete the Disk object via PowerShell as well as via portal.
– David Makogon
Mar 10 '16 at 16:11














Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
– Doug
Mar 10 '16 at 17:41




Thanks. In my case it ended up being a lot easier to simply release the lease in PowerShell, upload a new VHD to the same exact file name, and start the VM back up.
– Doug
Mar 10 '16 at 17:41




1




1




This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
– Ayan Mullick
Dec 22 '16 at 18:31




This script as recommended here didn't work for me. I installed Storage Explorer. Rt.Clicked on the container "Break Lease". And it worked....
– Ayan Mullick
Dec 22 '16 at 18:31












3 Answers
3






active

oldest

votes


















6














Login to the old portal and navigate to the Virtual Machines then the Images tab the url will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select the image and choose Delete on the bottom.



enter image description here



After that go to your storage and delete it.



You can also try the following which will remove blobs for a given container and then remove the container.



Add-AzureAccount
Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

$SubscriptionName = 'Your subsscription name'
Select-AzureSubscription -SubscriptionName $SubscriptionName

Get-AzureSubscription -Default

Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

$StorageAccountName = "Your storage account"
$StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
$ContainerName = "Your container name"
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

#Get a reference to all the blobs in the container.
$blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

#Remove lease on each Blob
$blobs | %{$_.ICloudBlob.BreakLease()}

#Delete blobs in a specified container.
$blobs| Remove-AzureStorageBlob

Remove-AzureStorageContainer -Container $ContainerName -Context $Context


If you want to break a seal on a blob you can use the How to break the locked lease of blob storage in Microsoft Azure (PowerShell)






share|improve this answer































    2














    The lease is likely from something like a VM, or something else using the Blog Storage. As a result manually releasing the lease could cause problems.



    With that said, the following PowerShell command should do the trick:



    Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()


    If its a VM, you should see the following post on removing the disk:
    Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request



    However, if you simply want to replace the drive used by every machine that uses the given blob, stopping the VM, releasing the lease, uploading a new image, and starting the VM appears to work.






    share|improve this answer



















    • 2




      You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
      – Yang Xia - Microsoft
      Mar 15 '16 at 2:25












    • Should be noted that this will not work on Premium Storage disks. Only standard ones.
      – superphonic
      Aug 30 at 15:22



















    2














    $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
    $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop
    $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop
    $blob = Get-AzureStorageBlob -Context $storageContext -Container $ContainerName -Blob $BlobName -ErrorAction Stop
    $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus;
    If($leaseStatus -eq "Locked")
    {
    $blob.ICloudBlob.BreakLease()
    Write-Host "Successfully broken lease on '$BlobName' blob."
    }
    Else
    {
    #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null)
    Write-Host "The '$BlobName' blob's lease status is unlocked."
    }


    If you want to a script for ARM resources you can use the
    How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35921299%2fhow-to-break-a-lease-on-blob-storage-in-azure-with-powershell%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      Login to the old portal and navigate to the Virtual Machines then the Images tab the url will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select the image and choose Delete on the bottom.



      enter image description here



      After that go to your storage and delete it.



      You can also try the following which will remove blobs for a given container and then remove the container.



      Add-AzureAccount
      Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

      $SubscriptionName = 'Your subsscription name'
      Select-AzureSubscription -SubscriptionName $SubscriptionName

      Get-AzureSubscription -Default

      Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

      $StorageAccountName = "Your storage account"
      $StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
      $ContainerName = "Your container name"
      $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

      #Get a reference to all the blobs in the container.
      $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

      #Remove lease on each Blob
      $blobs | %{$_.ICloudBlob.BreakLease()}

      #Delete blobs in a specified container.
      $blobs| Remove-AzureStorageBlob

      Remove-AzureStorageContainer -Container $ContainerName -Context $Context


      If you want to break a seal on a blob you can use the How to break the locked lease of blob storage in Microsoft Azure (PowerShell)






      share|improve this answer




























        6














        Login to the old portal and navigate to the Virtual Machines then the Images tab the url will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select the image and choose Delete on the bottom.



        enter image description here



        After that go to your storage and delete it.



        You can also try the following which will remove blobs for a given container and then remove the container.



        Add-AzureAccount
        Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

        $SubscriptionName = 'Your subsscription name'
        Select-AzureSubscription -SubscriptionName $SubscriptionName

        Get-AzureSubscription -Default

        Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

        $StorageAccountName = "Your storage account"
        $StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
        $ContainerName = "Your container name"
        $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

        #Get a reference to all the blobs in the container.
        $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

        #Remove lease on each Blob
        $blobs | %{$_.ICloudBlob.BreakLease()}

        #Delete blobs in a specified container.
        $blobs| Remove-AzureStorageBlob

        Remove-AzureStorageContainer -Container $ContainerName -Context $Context


        If you want to break a seal on a blob you can use the How to break the locked lease of blob storage in Microsoft Azure (PowerShell)






        share|improve this answer


























          6












          6








          6






          Login to the old portal and navigate to the Virtual Machines then the Images tab the url will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select the image and choose Delete on the bottom.



          enter image description here



          After that go to your storage and delete it.



          You can also try the following which will remove blobs for a given container and then remove the container.



          Add-AzureAccount
          Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

          $SubscriptionName = 'Your subsscription name'
          Select-AzureSubscription -SubscriptionName $SubscriptionName

          Get-AzureSubscription -Default

          Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

          $StorageAccountName = "Your storage account"
          $StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
          $ContainerName = "Your container name"
          $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

          #Get a reference to all the blobs in the container.
          $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

          #Remove lease on each Blob
          $blobs | %{$_.ICloudBlob.BreakLease()}

          #Delete blobs in a specified container.
          $blobs| Remove-AzureStorageBlob

          Remove-AzureStorageContainer -Container $ContainerName -Context $Context


          If you want to break a seal on a blob you can use the How to break the locked lease of blob storage in Microsoft Azure (PowerShell)






          share|improve this answer














          Login to the old portal and navigate to the Virtual Machines then the Images tab the url will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select the image and choose Delete on the bottom.



          enter image description here



          After that go to your storage and delete it.



          You can also try the following which will remove blobs for a given container and then remove the container.



          Add-AzureAccount
          Get-AzureSubscription | Format-Table SubscriptionName, IsDefault, IsCurrent, CurrentStorageAccountName

          $SubscriptionName = 'Your subsscription name'
          Select-AzureSubscription -SubscriptionName $SubscriptionName

          Get-AzureSubscription -Default

          Get-AzureStorageAccount | Format-Table -Property StorageAccountName, Location, AccountType, StorageAccountStatus

          $StorageAccountName = "Your storage account"
          $StorageAccountKey = (Get-AzureStorageKey -StorageAccountName $StorageAccountName).Primary
          $ContainerName = "Your container name"
          $Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

          #Get a reference to all the blobs in the container.
          $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context

          #Remove lease on each Blob
          $blobs | %{$_.ICloudBlob.BreakLease()}

          #Delete blobs in a specified container.
          $blobs| Remove-AzureStorageBlob

          Remove-AzureStorageContainer -Container $ContainerName -Context $Context


          If you want to break a seal on a blob you can use the How to break the locked lease of blob storage in Microsoft Azure (PowerShell)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 4:22









          OzBob

          2,3052135




          2,3052135










          answered Sep 17 '16 at 16:52









          Matija Grcic

          9,58835481




          9,58835481

























              2














              The lease is likely from something like a VM, or something else using the Blog Storage. As a result manually releasing the lease could cause problems.



              With that said, the following PowerShell command should do the trick:



              Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()


              If its a VM, you should see the following post on removing the disk:
              Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request



              However, if you simply want to replace the drive used by every machine that uses the given blob, stopping the VM, releasing the lease, uploading a new image, and starting the VM appears to work.






              share|improve this answer



















              • 2




                You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
                – Yang Xia - Microsoft
                Mar 15 '16 at 2:25












              • Should be noted that this will not work on Premium Storage disks. Only standard ones.
                – superphonic
                Aug 30 at 15:22
















              2














              The lease is likely from something like a VM, or something else using the Blog Storage. As a result manually releasing the lease could cause problems.



              With that said, the following PowerShell command should do the trick:



              Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()


              If its a VM, you should see the following post on removing the disk:
              Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request



              However, if you simply want to replace the drive used by every machine that uses the given blob, stopping the VM, releasing the lease, uploading a new image, and starting the VM appears to work.






              share|improve this answer



















              • 2




                You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
                – Yang Xia - Microsoft
                Mar 15 '16 at 2:25












              • Should be noted that this will not work on Premium Storage disks. Only standard ones.
                – superphonic
                Aug 30 at 15:22














              2












              2








              2






              The lease is likely from something like a VM, or something else using the Blog Storage. As a result manually releasing the lease could cause problems.



              With that said, the following PowerShell command should do the trick:



              Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()


              If its a VM, you should see the following post on removing the disk:
              Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request



              However, if you simply want to replace the drive used by every machine that uses the given blob, stopping the VM, releasing the lease, uploading a new image, and starting the VM appears to work.






              share|improve this answer














              The lease is likely from something like a VM, or something else using the Blog Storage. As a result manually releasing the lease could cause problems.



              With that said, the following PowerShell command should do the trick:



              Get-AzureRmStorageAccount -Name "STORAGE_ACCOUNT_NAME" | Get-AzureStorageBlob -name "CONTAINER_NAME").ICloudBlob.BreakLease()


              If its a VM, you should see the following post on removing the disk:
              Cannot delete blob: There is currently a lease on the blob and no lease ID was specified in the request



              However, if you simply want to replace the drive used by every machine that uses the given blob, stopping the VM, releasing the lease, uploading a new image, and starting the VM appears to work.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:10









              Community

              11




              11










              answered Mar 10 '16 at 15:55









              Doug

              2,87734065




              2,87734065








              • 2




                You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
                – Yang Xia - Microsoft
                Mar 15 '16 at 2:25












              • Should be noted that this will not work on Premium Storage disks. Only standard ones.
                – superphonic
                Aug 30 at 15:22














              • 2




                You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
                – Yang Xia - Microsoft
                Mar 15 '16 at 2:25












              • Should be noted that this will not work on Premium Storage disks. Only standard ones.
                – superphonic
                Aug 30 at 15:22








              2




              2




              You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
              – Yang Xia - Microsoft
              Mar 15 '16 at 2:25






              You might need the resource group name if you are using Get-AzureRmStorageAccount and the blob name for Get-AzureStorageBlob: Get-AzureRmStorageAccount -ResourceGroupName <resource group name> -Name <storage account name> | Get-AzureStorageBlob -Blob <blob name> -Container <container name>).ICloudBlob.BreakLease()
              – Yang Xia - Microsoft
              Mar 15 '16 at 2:25














              Should be noted that this will not work on Premium Storage disks. Only standard ones.
              – superphonic
              Aug 30 at 15:22




              Should be noted that this will not work on Premium Storage disks. Only standard ones.
              – superphonic
              Aug 30 at 15:22











              2














              $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
              $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop
              $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop
              $blob = Get-AzureStorageBlob -Context $storageContext -Container $ContainerName -Blob $BlobName -ErrorAction Stop
              $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus;
              If($leaseStatus -eq "Locked")
              {
              $blob.ICloudBlob.BreakLease()
              Write-Host "Successfully broken lease on '$BlobName' blob."
              }
              Else
              {
              #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null)
              Write-Host "The '$BlobName' blob's lease status is unlocked."
              }


              If you want to a script for ARM resources you can use the
              How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)






              share|improve this answer




























                2














                $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
                $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop
                $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop
                $blob = Get-AzureStorageBlob -Context $storageContext -Container $ContainerName -Blob $BlobName -ErrorAction Stop
                $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus;
                If($leaseStatus -eq "Locked")
                {
                $blob.ICloudBlob.BreakLease()
                Write-Host "Successfully broken lease on '$BlobName' blob."
                }
                Else
                {
                #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null)
                Write-Host "The '$BlobName' blob's lease status is unlocked."
                }


                If you want to a script for ARM resources you can use the
                How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)






                share|improve this answer


























                  2












                  2








                  2






                  $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
                  $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop
                  $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop
                  $blob = Get-AzureStorageBlob -Context $storageContext -Container $ContainerName -Blob $BlobName -ErrorAction Stop
                  $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus;
                  If($leaseStatus -eq "Locked")
                  {
                  $blob.ICloudBlob.BreakLease()
                  Write-Host "Successfully broken lease on '$BlobName' blob."
                  }
                  Else
                  {
                  #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null)
                  Write-Host "The '$BlobName' blob's lease status is unlocked."
                  }


                  If you want to a script for ARM resources you can use the
                  How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)






                  share|improve this answer














                  $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $selectedStorageAccount.ResourceGroupName -name $selectedStorageAccount.StorageAccountName -ErrorAction Stop)[0].value 
                  $storageContext = New-AzureStorageContext -StorageAccountName $selectedStorageAccount.StorageAccountName -StorageAccountKey $key -ErrorAction Stop
                  $storageContainer = Get-AzureStorageContainer -Context $storageContext -Name $ContainerName -ErrorAction Stop
                  $blob = Get-AzureStorageBlob -Context $storageContext -Container $ContainerName -Blob $BlobName -ErrorAction Stop
                  $leaseStatus = $blob.ICloudBlob.Properties.LeaseStatus;
                  If($leaseStatus -eq "Locked")
                  {
                  $blob.ICloudBlob.BreakLease()
                  Write-Host "Successfully broken lease on '$BlobName' blob."
                  }
                  Else
                  {
                  #$blob.ICloudBlob.AcquireLease($null, $null, $null, $null, $null)
                  Write-Host "The '$BlobName' blob's lease status is unlocked."
                  }


                  If you want to a script for ARM resources you can use the
                  How to break the locked lease of blob storage by ARM in Microsoft Azure(PowerShell)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 21 '16 at 5:39

























                  answered Sep 21 '16 at 5:29









                  frank tan

                  7314




                  7314






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35921299%2fhow-to-break-a-lease-on-blob-storage-in-azure-with-powershell%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen