Created
April 15, 2016 21:31
-
-
Save adumont/d8a71df2422297f40e569d4e7988802a to your computer and use it in GitHub Desktop.
List all Azure Virtual Networks
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
$Results = @() | |
Get-AzureRmSubscription | ForEach-Object { | |
$Subscription = $_ | |
Write-Host $Subscription.SubscriptionName | |
# We search all RM Virtual Networks | |
Select-AzureRmSubscription -SubscriptionName $Subscription.SubscriptionName | Out-Null | |
Get-AzureRmVirtualNetwork | ForEach-Object { | |
$VirtualNetwork = $_ | |
Write-Host "-- VirtualNetwork " $VirtualNetwork.Name $VirtualNetwork.AddressSpace.AddressPrefixes | |
$VirtualNetwork.Subnets | ForEach-Object { | |
$Subnet = $_ | |
Write-Host " -- Subnet " $Subnet.Name $Subnet.AddressPrefix | |
$Object = New-Object System.Object | |
$Object | Add-Member -type NoteProperty -name "Subscription" -Value $Subscription.SubscriptionName | |
$Object | Add-Member -type NoteProperty -name "Type" -Value "ARM" | |
$Object | Add-Member -type NoteProperty -name "VirtualNetwork" -Value $VirtualNetwork.Name | |
$Object | Add-Member -type NoteProperty -name "ResourceGroupName" -Value $VirtualNetwork.ResourceGroupName | |
$Object | Add-Member -type NoteProperty -name "Location" -Value $VirtualNetwork.Location | |
$Object | Add-Member -type NoteProperty -name "VNetAddress" -Value $VirtualNetwork.AddressSpace.AddressPrefixes | |
$Object | Add-Member -type NoteProperty -name "Subnet" -Value $Subnet.Name | |
$Object | Add-Member -type NoteProperty -name "SubnetAddress" -Value $Subnet.AddressPrefix | |
$Results += $Object | |
} | |
} | |
# We search all Classic Virtual Networks | |
Select-AzureSubscription -SubscriptionName $Subscription.SubscriptionName | Out-Null | |
$XML = Get-AzureVNetConfig | |
[ xml ]$fileContents = $XML.XMLConfiguration | |
$fileContents.DocumentElement.VirtualNetworkConfiguration.VirtualNetworkSites.VirtualNetworkSite | ForEach-Object { | |
$VirtualNetwork = $_ | |
if ( $VirtualNetwork.Name ) { | |
Write-Host "-- VirtualNetwork " $VirtualNetwork.Name $VirtualNetwork.AddressSpace.AddressPrefix | |
if ( $VirtualNetwork.Location -ne $null ) | |
{ | |
$Location=$VirtualNetwork.Location | |
} else { | |
if ( $VirtualNetwork.AffinityGroup -ne $null ) { | |
$Location=( Get-AzureAffinityGroup -Name $VirtualNetwork.AffinityGroup ).Location | |
} | |
} | |
$VirtualNetwork.Subnets.Subnet | ForEach-Object { | |
$Subnet = $_ | |
Write-Host " -- Subnet " $Subnet.Name $Subnet.AddressPrefix | |
$Object = New-Object System.Object | |
$Object | Add-Member -type NoteProperty -name "Subscription" -Value $Subscription.SubscriptionName | |
$Object | Add-Member -type NoteProperty -name "Type" -Value "Classic" | |
$Object | Add-Member -type NoteProperty -name "VirtualNetwork" -Value $VirtualNetwork.Name | |
$Object | Add-Member -type NoteProperty -name "ResourceGroupName" -Value $VirtualNetwork.ResourceGroupName | |
$Object | Add-Member -type NoteProperty -name "Location" -Value $Location | |
$Object | Add-Member -type NoteProperty -name "VNetAddress" -Value $VirtualNetwork.AddressSpace.AddressPrefix | |
$Object | Add-Member -type NoteProperty -name "Subnet" -Value $Subnet.Name | |
$Object | Add-Member -type NoteProperty -name "SubnetAddress" -Value $Subnet.AddressPrefix | |
$Results += $Object | |
} | |
} | |
} | |
} | |
$Results | FT | |
# $Results | D:\temp\Export-XLSX.ps1 D:\TEMP\VNet.xlsx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment