求可获取Azure WebApp的Vnet/子网、TLS版本及专用端点的PowerShell脚本
解决方案:获取Azure WebApp的Vnet/子网、TLS版本及专用端点信息
首先确保已安装并导入Azure PowerShell模块,且已登录Azure账号:
# 安装模块(如果未安装) Install-Module -Name Az.Websites -Force -AllowClobber Install-Module -Name Az.Network -Force -AllowClobber # 登录Azure Connect-AzAccount
以下是满足需求的PowerShell脚本,可批量或单个获取指定WebApp的目标字段:
# 可替换为你的资源组名称和WebApp名称,或留空获取订阅下所有WebApp $resourceGroupName = "你的资源组名称" $webAppName = "你的WebApp名称" # 获取WebApp信息 $webApps = if ($webAppName -and $resourceGroupName) { Get-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName } else { Get-AzWebApp } # 遍历处理每个WebApp foreach ($app in $webApps) { # 获取TLS版本 $tlsVersion = $app.SiteConfig.MinTlsVersion # 解析Vnet和子网信息 $vnetName = $null $subnetName = $null if ($app.VirtualNetworkSubnetId) { $subnetParts = $app.VirtualNetworkSubnetId -split '/' $vnetName = $subnetParts[$subnetParts.IndexOf('virtualNetworks') + 1] $subnetName = $subnetParts[$subnetParts.IndexOf('subnets') + 1] } # 获取关联的专用端点信息 $privateEndpoints = Get-AzPrivateEndpoint | Where-Object { $_.PrivateLinkServiceConnections.PrivateLinkServiceId -eq $app.Id } | Select-Object Name, ResourceGroupName, Location # 输出自定义对象 [PSCustomObject]@{ WebAppName = $app.Name ResourceGroupName = $app.ResourceGroup TLSVersion = $tlsVersion ?? "未配置" VnetName = $vnetName ?? "未集成Vnet" SubnetName = $subnetName ?? "无" PrivateEndpoints = if ($privateEndpoints) { $privateEndpoints } else { "无专用端点" } } }
脚本说明:
- TLS版本:直接从WebApp的
SiteConfig.MinTlsVersion属性读取,返回当前配置的最低TLS版本(如TLS1_2、TLS1_3)。 - Vnet/子网:通过解析
VirtualNetworkSubnetId属性的URI路径,拆分出Vnet和子网名称;若WebApp未集成Vnet则返回提示文本。 - 专用端点:通过
Get-AzPrivateEndpoint查询所有与当前WebApp资源ID关联的专用端点,返回端点名称、资源组和位置信息。 - 支持单个WebApp查询或批量获取订阅下所有WebApp的信息,只需调整
$resourceGroupName和$webAppName参数即可。
内容的提问来源于stack exchange,提问作者User Name
相关产品推荐
相关产品推荐

