Thursday, May 15, 2014

Finding and deleting the storage accounts in an Azure lab.

In a previous article I started building up a cleanup script for the lab.  Since it needs to be torn down in the reverse order of how it is built up, I stared out by removing the network.  The next part is to remove the storage account, but that isn’t quite as easy.  Because they need to have globally unique names, I appended a GUID stripped of the dashes on to the lab name and trimmed it to 25 characters.  The good news is that the Label is the lab name.  They can be duplicated.  That means that I can use the Label if I don’t mind crunching some duplicates.  Here is the script:
Get-AzureStorageAccount | Where-Object { $_.label -eq $labName } | Remove-AzureStorageAccount 

The first part retrieves a list of all of the storage accounts.  Take a look at the following to get a sense of the data retrieved:
Get-AzureStorageAccount | Select Label

With this data, we select only those with a Label matching the lab name:
Get-AzureStorageAccount | Where-Object { $_.label -eq $labName } | select Label


Now that we have narrowed it down to two, we just pass those values into the remove.

No comments:

Post a Comment