You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查询Azure订阅内Azure Functions的总数(非Function App)

统计Azure订阅内Azure Functions总数的实现方案

Azure Resource Graph的局限

Azure Resource Graph仅能查询Azure顶层资源(如Function App),而Function App内部的单个Azure Functions属于应用级资源,不在Resource Graph的资源类型覆盖范围内,因此无法直接通过它统计底层函数数量。

可行方案:结合Resource Graph与脚本查询

可以先通过Resource Graph获取订阅内所有Function App的信息,再用Azure CLI或PowerShell逐个查询每个App包含的函数数量并汇总。

方案1:Azure CLI脚本

  1. 导出所有Function App的资源ID:
az graph query -q "resources | where type == 'microsoft.web/sites' and kind contains 'functionapp' | project id" --output tsv > functionapps.txt
  1. 遍历统计函数总数:
total=0
while read -r appId; do
    appName=$(echo "$appId" | awk -F '/' '{print $9}')
    resourceGroup=$(echo "$appId" | awk -F '/' '{print $5}')
    funcCount=$(az functionapp function list --name "$appName" --resource-group "$resourceGroup" --output tsv | wc -l)
    total=$((total + funcCount))
done < functionapps.txt
echo "Total Azure Functions: $total"

方案2:PowerShell脚本

  1. 获取所有Function App的详细信息:
$functionApps = Search-AzGraph -Query "resources | where type == 'microsoft.web/sites' and kind contains 'functionapp' | project id, name, resourceGroup"
  1. 累加所有函数数量:
$totalFunctions = 0
foreach ($app in $functionApps) {
    $functions = Get-AzFunctionAppFunction -ResourceGroupName $app.resourceGroup -Name $app.name
    $totalFunctions += $functions.Count
}
Write-Host "Total Azure Functions: $totalFunctions"

注意事项

  • 需具备Microsoft.Web/sites/functions/read权限才能查询Function App内的函数。
  • 若订阅内Function App数量较多,脚本执行时间会延长,可考虑添加并行处理提升效率。

内容的提问来源于stack exchange,提问作者user20056090

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 11:15:43