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: