79615418

Date: 2025-05-10 11:17:42
Score: 0.5
Natty:
Report link

using Get-AzMetric with -Dimension

Using -MetricFilter and checking the dimension values with Get-AzMetricDefinition, I retrieved Availability metrics by ApiName and filtered the result to only show timestamps where Availability was 100 just like how it works in the Azure Portal when filtering by API operations.

$results = Get-AzMetric -ResourceId $resourceId `
  -MetricName "Availability" `
  -Dimension "ApiName" `
  -TimeGrain ([TimeSpan]::FromHours(1)) `
  -StartTime (Get-Date).AddDays(-7) `
  -EndTime (Get-Date)
foreach ($ts in $results.Timeseries) {
    $apiName = $ts.Metadatavalues[0].Value
    $filteredData = $ts.Data | Where-Object { $_.Average -eq 100 }
    if ($filteredData) {
        Write-Host "`n--- API: $apiName ---`n"
        foreach ($dp in $filteredData) {
            Write-Host "Time: $($dp.TimeStamp) | Availability: $($dp.Average)"
        }
    }
}

Output:

enter image description here

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Harshitha Bathini