Skip to content

Instantly share code, notes, and snippets.

@cveld
Created November 7, 2022 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cveld/57df0c4517a14b5e0243a91a9e32fe58 to your computer and use it in GitHub Desktop.
Save cveld/57df0c4517a14b5e0243a91a9e32fe58 to your computer and use it in GitHub Desktop.
Export Vwan Topology - all cidrs of underlying vnet connections
# You can run this script like so:
# . .\vwan-topology-export.ps1 -VirtualWanName vwan-platform-prd-weu-001 | select -Property Component, Name, Cidr, Parent, ParentType | ConvertTo-Csv | Set-Content output.csv
param(
[Parameter(Mandatory=$true)]
$VirtualWanName
)
$vwan = Get-AzVirtualWan -Name $VirtualWanName
$vwanresource = Get-AzResource -ResourceId $vwan.id
$split = $vwanresource.Properties.virtualHubs[0].Id.split("/")
$hub = Get-AzVirtualHub -resourcegroupname $split[4] -name $split[8]
New-Object -TypeName PSObject -Property @{
Component = "Hub"
Cidr = $hub.AddressPrefix
Name = $VirtualWanName
}
$conn = $hub.VirtualNetworkConnections
$conn | ForEach-Object {
$vnet = Get-AzResource -ResourceId $_.RemoteVirtualNetwork.Id
$vnet.Properties.addressSpace.addressPrefixes | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Component = "Vnet"
Name = $vnet.Name
Cidr = $_
Parent = $VirtualWanName
ParentType = "Hub"
}
}
$prop = $vnet.Properties.subnets
$prop | ForEach-Object {
New-Object -TypeName PSObject -Property @{
Component = "Subnet"
Name = $_.Name
Parent = $vnet.Name
ParentType = "Vnet"
Cidr = $_.properties.addressPrefix
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment