how to get storage accounts capacity usage for 1400 storage accounts

Ayisha Tabbassum 0 Reputation points
2024-02-28T17:55:37.5666667+00:00

how to get storage accounts capacity usage for 1400 storage accounts

Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
231 questions
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,709 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 10,845 Reputation points MVP
    2024-02-28T18:03:38.22+00:00

    You can use scripting:

    # Define your subscription ID
    $subscriptionId = "YourSubscriptionId"
    # Get all storage accounts in the subscription
    $storageAccounts = Get-AzStorageAccount -SubscriptionId $subscriptionId
    # Loop through each storage account
    foreach ($storageAccount in $storageAccounts) {
        # Get storage account name
        $storageAccountName = $storageAccount.StorageAccountName
        # Get storage account key (assuming you have the necessary permissions)
        $storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccountName).Value[0]
        # Create a storage context
        $context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
        # Get storage account properties
        $properties = Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccountName
        # Extract relevant information (adjust as needed)
        $capacity = $properties.PrimaryEndpoints.Blob + "?comp=properties"
        $capacityInfo = Invoke-RestMethod -Uri $capacity -Method GET -Headers @{"x-ms-version"="2020-08-04"} -UseBasicParsing
        # Output storage account and capacity information
        Write-Host "Storage Account: $($storageAccount.StorageAccountName)"
        Write-Host "Capacity Usage: $($capacityInfo.totalCapacity)"
        Write-Host "---------------------------"
    }
    
    

    hth Marcin

    0 comments No comments