question

CharlesTIU-2518 avatar image
0 Votes"
CharlesTIU-2518 asked ·

Storage account not in use

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
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sumarigo-MSFT avatar image
0 Votes"
Sumarigo-MSFT answered ·

@CharlesTIU-2518 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.



capture.png (71.1 KiB)
capture.png (80.4 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CharlesTIU-2518 avatar image
0 Votes"
CharlesTIU-2518 answered ·

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....

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sumarigo-MSFT avatar image
0 Votes"
Sumarigo-MSFT answered ·

@CharlesTIU-2518 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.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.