使用Powershell获取有关VNET、子网、NSG和路由表的Azure信息

irlmq6kh  于 2023-01-14  发布在  Shell
关注(0)|答案(1)|浏览(140)

这个post正是我所需要的,但我想添加NSG和路由表信息:

$subs = Get-AzSubscription 
foreach ($Sub in $Subs) {
    Write-Host "***************************"
    Write-Host " "
    $Sub.Name 

    $SelectSub = Select-AzSubscription -SubscriptionName $Sub.Name

    $VNETs = Get-AzVirtualNetwork 
    foreach ($VNET in $VNETs) {
        Write-Host "--------------------------"
        Write-Host " "
        Write-Host "   vNet: " $VNET.Name 
        Write-Host "   AddressPrefixes: " ($VNET).AddressSpace.AddressPrefixes

        $vNetExpanded = Get-AzVirtualNetwork -Name $VNET.Name -ResourceGroupName $VNET.ResourceGroupName -ExpandResource 'subnets/ipConfigurations' 

        foreach($subnet in $vNetExpanded.Subnets)
        {
            Write-Host "       Subnet: " $subnet.Name
            Write-Host "          Connected devices " $subnet.IpConfigurations.Count
            foreach($ipConfig in $subnet.IpConfigurations)
            {
                Write-Host "            " $ipConfig.PrivateIpAddress
            }
        }

        Write-Host " " 
    } 
}

我试着添加变量来反映它,但我想我不能让它工作。

0vvn1miw

0vvn1miw1#

添加以下脚本片段以获取NetworkSecurityGroup(NSG)和路由表信息:

$nsgs = Get-AzNetworkSecurityGroup
foreach ($nsg in $nsgs) {
Write-Host "   nsg: " $nsg.Name
$networksecuritygroup = Get-AzNetworkSecurityGroup -Name $nsg -ResourceGroupName $nsg.ResourceGroupName
}
$rts = Get-Azroutetable
foreach ($rt in $rts) {
Write-Host "  rt: " $rt.Name
$routetableinfo = Get-Azroutetable -Name $rt -ResourceGroupName $rt.ResourceGroupName
}

输出:

相关问题