How to split rent on Blob Storage in Azure using PowerShell?

How to break leasing on an item in Blob using PowerShell?

I get the following when trying to load something on top of 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 
+6
source share
3 answers

Log in to the old portal and go to Virtual Machines and then the Images tab. The URL will be https://manage.windowsazure.com/@yourname.onmicrosoft.com#Workspaces/VirtualMachineExtension/images. Select an image and select Delete at the bottom.

enter image description here

After that, go to your repository and delete it.

You can also try the following, which will remove the blob for this container and then delete 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 #Delete blobs in a specified container. $blobs| Remove-AzureStorageBlob Remove-AzureStorageContainer -Container $ContainerName -Context $Context 

If you want to break the print on blob, you can use How to block the blocked lease of blob storage in Microsoft Azure (PowerShell)

+5
source

The lease most likely comes from something like a virtual machine or something else that uses blog storage. As a result, manually exempting rents can 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 it is VM, you should see the following message about removing the disk: Unable to delete blob: currently there is a lease on blob, and the request does not specify a lease identifier

However, if you just want to replace the disk used by each machine using this blob, stop the virtual machine, release the lease, upload a new image and start the virtual machine.

+2
source
 $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 lease status is unlocked." } 

If you want to use script resources for ARM, you can use How to break a blocked blob storage rental using ARM in Microsoft Azure (PowerShell)

+1
source

All Articles