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

如何用PowerShell列出Azure订阅指定区域的虚拟网络

列出指定区域内的Azure虚拟网络

基础前提

确保你已经安装了Az PowerShell模块,并且通过Connect-AzAccount完成了Azure账户登录,同时切换到目标订阅(如果有多个订阅):

# 切换到目标订阅(替换为你的订阅ID或名称)
Set-AzContext -Subscription "Your-Subscription-ID-or-Name"

单个指定区域的查询

直接使用Get-AzVirtualNetwork命令,通过-Location参数指定目标区域即可:

# 替换为你要查询的区域名称,比如"eastus"、"southeastasia"
$targetRegion = "eastus"

# 获取指定区域的所有虚拟网络
$vnsInRegion = Get-AzVirtualNetwork -Location $targetRegion

# 输出结果(默认显示名称、资源组、位置等信息)
$vnsInRegion

# 如果需要仅输出关键属性,比如名称、资源组、地址空间
$vnsInRegion | Select-Object Name, ResourceGroupName, Location, AddressSpace

遍历已获取的区域列表查询

如果你已经有了订阅内虚拟网络所属的所有区域列表,可以循环遍历每个区域并查询:

# 假设你已获取的区域列表存储在$vnRegions变量中
$vnRegions = Get-AzVirtualNetwork | Select-Object -ExpandProperty Location -Unique

# 遍历每个区域查询虚拟网络
foreach ($region in $vnRegions) {
    Write-Host "`n=== 区域 $region 下的虚拟网络 ==="
    Get-AzVirtualNetwork -Location $region | Select-Object Name, ResourceGroupName, AddressSpace
}

扩展:导出结果到CSV

如果需要将指定区域的虚拟网络信息导出到文件:

$targetRegion = "eastus"
Get-AzVirtualNetwork -Location $targetRegion | 
    Select-Object Name, ResourceGroupName, Location, @{Name="AddressPrefixes"; Expression={$_.AddressSpace.AddressPrefixes -join ","}} |
    Export-Csv -Path "VNs-In-$targetRegion.csv" -NoTypeInformation -Encoding UTF8

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 05:42:03