Storage account not in use

Charles Tiu 41 Reputation points
2021-03-10T03:23:53.793+00:00

Hi, we have just takeover a subscription from another team and we are doing cleanup of VM, NICS, disk and storage account. There's >50 storage account but no one knows which account is still in use. How can we determine which storage account are no longer in use so that we can remove them.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,714 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sumarigo-MSFT 43,801 Reputation points Microsoft Employee
    2021-03-10T07:30:29.913+00:00

    anonymous user Welcome to Microsoft Q&A, Thank you for posting your query!

    1. Firstly, you may check usage capacity and transaction of the Storage account through Azure Monitor based on the subscription which provided the details which hasn't been used from when and how much data does it holds : Navigate to Azure portal -> Monitor -> Storage accounts: Then select your subscription; For storage accounts, select "All" -> At last, click "Capacity"(You can also select the time range). The screenshot as below:
      76172-capture.png

    Note: You should calculate the total space used one by one, there is no such built-in feature. Or you can write a code calculate total space used one by one.

    1. What you could do is get the most recent modified container from the LastModified property, then check if this timestamp is less than the current date minus 90 days.

      Set current context to subscription

      Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

      Go through every storage account in your subscription

      foreach ($storageAccount in Get-AzStorageAccount) {
      $storageAccountName = $storageAccount.StorageAccountName
      $resourceGroupName = $storageAccount.ResourceGroupName
      # Get key1 storage account key  
      $storageAccountKey = (Get-AzStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroupName).Value[0]  
      
      # Create storage account context using above key  
      $context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  
      
      # Get the most recently accessed container by sorting by LastModified and picking the last object  
      $lastModified = Get-AzStorageContainer -Context $context   
          | Sort-Object -Property @{Expression = {$_.LastModified.DateTime}}  
              | Select-Object -Last 1 -ExpandProperty LastModified  
      
      # Remove storage account if it is older than 90 days  
      if ($lastModified.DateTime -lt (Get-Date).AddDays(-90)) {  
          Remove-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -Force -WhatIf  
      }  
      
      }
    2. You can also check in Azure Metrics for more detailed information based on the region: 76203-capture.png

    If you still find any issues, please let us know we would like to work closer on this issue.

    Hope this helps!


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


2 additional answers

Sort by: Most helpful
  1. Charles Tiu 41 Reputation points
    2021-03-10T08:14:28.663+00:00

    Hi, thanks for the guide. Can I assume those with low transaction value as inactive.
    If inactive, what are the possible reason why there data in B/KiB/MiB... over period of 7 days....

    I have ran the script for 'inactive containers'... but all are flag as active....

    0 comments No comments

  2. Sumarigo-MSFT 43,801 Reputation points Microsoft Employee
    2021-03-10T08:41:11.603+00:00

    anonymous user You can custom the data for many months and check which is inactive and delete those account, If not take a backup of azure storage in active account or move those data to the active storage account using Azcopy or Azure Storage Explorer

    Choose an Azure solution for data transfer

    If inactive, what are the possible reason why there data in B/KiB/MiB... over period of 7 days>

    That much amount of data has been saved in your storage account it's measured on B/KiB/MiB, Storage account would be active but there won't be any transaction for months.

    Kindly let us know if you still have more questions on this. I wish to engage with you offline for a closer look and provide a quick and specialized assistance, please send an email with subject line “Attn:subm”to AzCommunity[at]Microsoft[dot]com referencing this thread and the Azure subscription ID, I will follow-up with you.

    Thanks for your patience and co-operation.

    Hope this helps!

    -----------------------------------------------------------------------------------------------------------------------------

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments