Hello there,
Use the following PowerShell script to retrieve CPU and memory metrics for all Azure App Services in your subscription:
$resourceType = "Microsoft.Web/sites"
$metricNames = @("CpuPercentage", "MemoryPercentage")
$appServices = Get-AzResource -ResourceType $resourceType
foreach ($appService in $appServices) {
$resourceId = $appService.ResourceId
$metricData = Get-AzMetric -ResourceId $resourceId -MetricName $metricNames -TimeRange (New-TimeSpan -Minutes 5)
Write-Host "Metrics for App Service: $($appService.Name)"
foreach ($metric in $metricData) {
$metric.Name.Value
$metric.Data
Write-Host
}
}
This script retrieves the CPU and memory metrics for each App Service within the last 5 minutes. You can adjust the $metricNames array to include additional metrics if needed.
I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–