Skip to content

Instantly share code, notes, and snippets.

@Torxsmind
Created April 20, 2020 15:05
Show Gist options
  • Select an option

  • Save Torxsmind/6468fdce5d74162a61aa2fa7908b23f6 to your computer and use it in GitHub Desktop.

Select an option

Save Torxsmind/6468fdce5d74162a61aa2fa7908b23f6 to your computer and use it in GitHub Desktop.
Get all Azure Subnet information
$now = Get-Date -UFormat "%Y-%m-%d_%H-%M-%S"
$filepath = 'C:\temp\Azure_vnet_export_' + $now + '.csv'
$subs = Get-AzSubscription
foreach ($sub in $subs) {
Select-AzSubscription -Subscription $sub.Name
$VNETs = Get-AzVirtualNetwork
foreach ($VNET in $VNETs) {
$subnets = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet
foreach ($subnet in $Subnets) {
$data = @{
'SubscriptionName' = $Sub.Name;
'VnetName' = $VNET.Name;
'VnetAddressPrefixes' = (($VNET).AddressSpace.AddressPrefixes -join ' ');
'VnetLocation' = $Vnet.location;
'SubnetName' = $subnet.name;
'SubnetAddressPrefixes' = ($subnet.AddressPrefix -join ' ')
}
$obj = New-Object -Type PSObject -Prop $data
$obj | Export-Csv -Path $filepath -NoTypeInformation -append
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment