Thanks @Ravi Kanth Koppala .
I wrote a PS script to fetch the list of storage accounts that have classic metrics enabled.
Below is the script for fellow Azure enthusiasts who might be looking for the same.
NOTE:
- This checks if the Hourly Metrics is enabled or not, which I understood from the documentation that Hourly Metrics are part of Classic metrics and is not present for SA that have Azure monitor metrics enabled.
- This checks only for the Blob and File types of storage account, modify the script to include other types (Table, Queue, Web, DFS,...) as needed.
$az_tenant = Read-Host "Enter the Directory ID of Azure"
Connect-AzAccount -TenantId $az_tenant -WarningAction SilentlyContinue | Out-Null
# Get a list of subscriptions
$subscriptions = Get-AzSubscription -TenantId $az_tenant
# Create an empty array to store the results
$results = @()
# Iterate through each subscription
foreach ($subscription in $subscriptions) {
Select-AzSubscription -SubscriptionName $subscription -WarningAction SilentlyContinue | Out-Null
# Get all the storage accounts in the subscription
$storageAccounts = Get-AzStorageAccount
# Loop through each storage account and check if it has classic metrics enabled
foreach ($account in $storageAccounts) {
if ($account.PrimaryEndpoints.Blob) {
$diagnosticSettings = $account | Get-AzStorageServiceMetricsProperty -ServiceType Blob -MetricsType Hour
} else {
# Get the diagnostic settings for the storage account
$diagnosticSettings = $account | Get-AzStorageServiceMetricsProperty -ServiceType File -MetricsType Hour
}
# Check if the diagnostic settings contain any metrics data
if ($diagnosticSettings.MetricsLevel) {
# Create a custom object to store the information for each storage account
$object = [PSCustomObject]@{
SubscriptionName = $subscription.Name
AccountName = $account.StorageAccountName
Kind = $account.Kind
ClassicMetrics = "Enabled"
MetricsLevel = $diagnosticSettings.MetricsLevel
MetricsRetentionDays = $diagnosticSettings.RetentionDays
}
} else {
# Create a custom object to store the information for each storage account
$object = [PSCustomObject]@{
SubscriptionName = $subscription.Name
AccountName = $account.StorageAccountName
Kind = $account.Kind
ClassicMetrics = "Disabled"
MetricsLevel = $diagnosticSettings.MetricsLevel
MetricsRetentionDays = $diagnosticSettings.RetentionDays
}
}
# Add the object to the results array
$results += $object
}
}
# Convert the results array to a table and display it
$results | Format-Table -AutoSize