Home > Blockchain >  Getting Azure information with Powershell about VNET, Subnet, NSG & route Table
Getting Azure information with Powershell about VNET, Subnet, NSG & route Table

Time:01-13

This post is exactly what I need, but I would like to add NSG and Route table information:

$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 " " 
    } 
}

I tried adding the variables to reflect it, but I guess I cant get it to work.

CodePudding user response:

Add below script snippet to get NetworkSecurityGroup(NSG) and Route table information:

$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
}

Output:

enter image description here

enter image description here

enter image description here

  • Related