列出与虚拟网络集成的 Azure 资源

时间:2021-02-02 10:21:30

标签: azure azure-web-app-service azure-virtual-network

我在 Azure 中设置了一个具有多个子网的虚拟网络 (VNet)。我还在此 VNet 的多个应用服务中使用 VNet 集成。应用服务在不同的应用服务计划上运行。

是否可以列出在此 VNet 上使用 VNet 集成的所有应用服务(可能还有其他 Azure 资源)?我知道我可以在每个 App Service 的网络设置中查看 VNet 集成,但是当要查看数百个 App Service 时,这种方法太麻烦了。

1 个答案:

答案 0 :(得分:1)

这是一个脚本,用于列出订阅中启用了 VNet 集成的所有应用服务和功能应用。来自this blog的参考。

$AppServices = @(
az webapp list | ConvertFrom-Json
az functionapp list | ConvertFrom-Json
)
$VNetAppServices = foreach ($App in $AppServices) {    
    $Apps = az webapp vnet-integration list --n $App.Name -g $App.ResourceGroup
    if ($Apps -ne "[]") {
        $ServerFarm = $App.appServicePlanId -split '/'
        $VNetIntData = $Apps | ConvertFrom-Json
        $VNet = $VNetIntData.VnetResourceID -split '/'
        [PSCustomObject]@{
            AppServiceName = $App.Name
            ServerFarm     = $ServerFarm[8]
            ResourceGroup  = $App.ResourceGroup
            Location       = $App.Location
            VNetName       = $VNet[8]
            SubnetName     = $VNetIntData.name  
            VNetRG         = $VNet[4]       
        }
    }    
}
$VNetAppServices | ft

enter image description here