0

I've recently been learning Azure Resource Manager template based deployment, and as a result I am deploying and removing a lot of VMs as I refine my ResourceManager templates. I have made a PowerShell script to delete a given VM,LoadBalancer,PublicIPAddress,NetworkInterface,etc but I can't find an equivalent cmdlet for removing a VHD / blob / from an AzureRM Storage account.

Is there an AzureRM PowerShell way to delete a VHD file stored in an Azure ResourceManager Storage account? Or is this yet to be implemented? If not, are there any command line alternatives such as Azure CLI or a workaround?

I've looked at:

Get-Command -Module AzureRM.Storage 

This shows:

CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-AzureRmStorageAccount 1.1.3 AzureRm.Storage Cmdlet Get-AzureRmStorageAccountKey 1.1.3 AzureRm.Storage Cmdlet Get-AzureRmStorageAccountNameAvailability 1.1.3 AzureRm.Storage Cmdlet Get-AzureRmStorageUsage 1.1.3 AzureRm.Storage Cmdlet New-AzureRmStorageAccount 1.1.3 AzureRm.Storage Cmdlet New-AzureRmStorageAccountKey 1.1.3 AzureRm.Storage Cmdlet Remove-AzureRmStorageAccount 1.1.3 AzureRm.Storage Cmdlet Set-AzureRmCurrentStorageAccount 1.1.3 AzureRm.Storage Cmdlet Set-AzureRmStorageAccount 1.1.3 AzureRm.Storage 

... which doesn't have what I want. The closest would be adding and removing an entire storage account, but since I'm deploying from a custom template I believe I am limited to storing the VM VHD in the same storage account as the template (please correct me if I'm wrong). By contrast, the Azure.Storage module has *StorageFile/Blob/Container cmdlets. Given I see classic Azure cmdlets that sound like what I want, but no AzureRM equivalents, I suspect the answer is "no" for the moment.

For reference, I'm running Windows 10, and have installed the latest AzureRM PowerShell module from the PowerShell Gallery within the past couple of weeks (AzureRM Module 1.6.0, AzureRM.Storage 1.1.3)

1

1 Answer 1

2

You can pass the Context to the Remove-AzureStorageBlob.

$RGName = "stlvm" $SAName = "stlvmstorage" $ConName = "testcontainer" $BlobName = "Test02.txt" $Keylist = Get-AzureRmStorageAccountKey -ResourceGroupName $RGName -StorageAccountName $SAName $Key = $Keylist[0].Value $Ctx = New-AzureStorageContext -StorageAccountName $SAName -StorageAccountKey $Key Get-AzureStorageBlob -Container $ConName -Context $Ctx | select Name Remove-AzureStorageBlob -Container $ConName -Blob $BlobName -Context $Ctx Get-AzureStorageBlob -Container $ConName -Context $Ctx | select Name 

I've tested it on my lab server. It works for me.

Azure

1
  • Right on, that did the trick. Having never used the old "ASM" Azure Cmdlets much, I didn't realize to what extent they could interoperate. This also is a better and more complete answer than the one linked in a comment. Thanks! Commented Jul 30, 2016 at 3:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.