none
Find unused Storage Accounts

    Question

  • Is there a way of finding unused storage accounts (disks) in Azure so they can be deleted.  I've created and removed several VMs and don't know which disks refer to active machines.

    Thanks

    Thursday, November 24, 2016 3:38 PM

Answers

  • Hi,

    Thank you for posting here! We are happy to assist you.

    1. Are you using classic VM or an ARM VM?

    Launch the Portal and check which all VM are you using/running. Once you click on the running VM select disk option. There you will find the storage account information. Make a note of those storage account; Later you can delete the unused storage account


    Regards,
    Sumanth BM

    Thursday, November 24, 2016 6:51 PM
    Moderator

All replies

  • Hi,

    Thank you for posting here! We are happy to assist you.

    1. Are you using classic VM or an ARM VM?

    Launch the Portal and check which all VM are you using/running. Once you click on the running VM select disk option. There you will find the storage account information. Make a note of those storage account; Later you can delete the unused storage account


    Regards,
    Sumanth BM

    Thursday, November 24, 2016 6:51 PM
    Moderator
  • Hi

    If your storage accounts are based on ARM mode, you could use the below cmdlets.

    ##your storage account name
    
    $storageAccountName =
    "shuidisks324"
    
    ##your resource group name
    
    $rgname= "shui"
    
    ##your container name
    
    $Container =
    "vhds"
    
    $Key =
    Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName
    $rgname
    
    $storageAccountKey =
    $key[0].Value
    
    $context =New-AzureStorageContext
    -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
    
    $blob=Get-AzureStorageBlob
    -Container $Container -Context $context -Blob *.vhd
    
    foreach($i in
    $blob){"blobname:"+$i.Name+" 
    status:"+$i.ICloudBlob.Properties.LeaseState }

    status: Available means the vhd is not used, you could delete.

    If your storage accounts are based on ASM mode, you could use the below cmdlets.

    $storageAccountName =
    "shuiclassic4070"
    
    $storageAccountKey =(
    Get-AzureStorageKey -StorageAccountName $storageAccountName ).Primary
    
    $context
    =New-AzureStorageContext -StorageAccountName $storageAccountName
    -StorageAccountKey $storageAccountKey
    
    $blob=Get-AzureStorageBlob
    -Container $Container -Context $context -Blob *.vhd
    
    foreach($i in
    $blob){"blobname:"+$i.Name+" 
    status:"+$i.ICloudBlob.Properties.LeaseState }

    If you still have questions, welcome to post back here. Thanks.

    Regards,

    Walter


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, November 25, 2016 2:38 AM
  • Thanks for the reply - worked great :)
    Friday, November 25, 2016 1:50 PM