Created
April 20, 2020 15:05
-
-
Save Torxsmind/6468fdce5d74162a61aa2fa7908b23f6 to your computer and use it in GitHub Desktop.
Get all Azure Subnet information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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