'Get\List all azure subnets
I tried creating a script to get all azure subnets and their details.
How to get all azure subnets including their address and associated NSG?
Solution 1:[1]
$list = $null
$list = @()
$vnets = Get-AzVirtualNetwork
foreach ($vnet in $vnets) {
$subnets = $vnet.Subnets.name
foreach ($subnet in $subnets){
$SubnetDetails = Get-AzVirtualNetworkSubnetConfig -Name $subnet -VirtualNetwork $vnet
$list += [PSCustomObject]@{
VNETName = $vnet.Name
VNETAddressSpaces = $vnet.AddressSpace.AddressPrefixes -join ', '
SubnetName = $SubnetDetails.name
SubnetsPrefix = $SubnetDetails.AddressPrefix -join ''
SubnetNSG = if($SubnetDetails.NetworkSecurityGroup -eq $Null) {"No NSG"} else{$SubnetDetails.NetworkSecurityGroup.id.split('/')[8]}
SubnetNSGID = if($SubnetDetails.NetworkSecurityGroup -eq $Null) {"No NSG"} else{$SubnetDetails.NetworkSecurityGroup.id}
}
}
}
$list | ogv
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark Sampayan |
