Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gather ExpressRoute Circuits with Global Reach enabled. This does account for multiple subscriptions as well.
#Requires -Modules az
Connect-AzAccount
$ERGREnabled = @()
$GRDataFull = @()
$ERCircuits = @()
$Subs = Get-AzSubscription
Foreach ($Sub in $Subs){
Select-AzSubscription $Sub
$ERCircuits += Get-AzExpressRouteCircuit
}
Foreach ($ERCircuit in $ERCircuits){
If ($ERCircuit.GlobalReachEnabled -eq $true -or ($ERCircuit | Get-AzExpressRouteCircuitConnectionConfig))
{
$Data = "" | Select-Object SubId, ERResourceGroup, ERCircuitName, GRName, GRAddressPrefix, PeerERResourceGroup, PeerExpressRoute, PeerSubId, SPName, PeeringLocation, Bandwidth, GlobalReachEnabled, ServiceKey
$Data.SubId = $ERCircuit.Id.split("/")[2]
$Data.ERResourceGroup = $ERCircuit.Id.split("/")[4]
$Data.ERCircuitName = $ERCircuit.Name
If ($ERCircuit | Get-AzExpressRouteCircuitConnectionConfig -ErrorAction:SilentlyContinue)
{
$GRData = ($ERCircuit | Get-AzExpressRouteCircuitConnectionConfig -ErrorAction:SilentlyContinue)
$Data.GRName = $GRData.Name
$Data.GRAddressPrefix = $GRData.AddressPrefix
If ($GRData.PeerExpressRouteCircuitPeering.count -gt 1)
{ $Data.PeerERResourceGroup = "Multiple Objects"
$Data.PeerExpressRoute = $GRData.PeerExpressRouteCircuitPeering
}
Else {
$Data.PeerERResourceGroup = $GRData.PeerExpressRouteCircuitPeering.Id.split("/")[4]
$Data.PeerExpressRoute = $GRData.PeerExpressRouteCircuitPeering.Id.split("/")[8]
}
$Data.PeerSubId = $GRData.PeerExpressRouteCircuitPeering.Id.split("/")[2]
}
Else
{
$Data.GRName = "No Data Found - Possibly Customer Initiated"
$Data.GRAddressPrefix = "No Data Found - Possibly Customer Initiated"
$Data.PeerERResourceGroup = "No Data Found - Possibly Customer Initiated"
$Data.PeerExpressRoute = "No Data Found - Possibly Customer Initiated"
$Data.PeerSubId = "No Data Found - Possibly Customer Initiated"
}
$Data.SPName = $ERCircuit.ServiceProviderProperties.ServiceProviderName
$Data.PeeringLocation = $ERCircuit.ServiceProviderProperties.PeeringLocation
$Data.Bandwidth = $ERCircuit.ServiceProviderProperties.BandwidthInMbps
$Data.GlobalReachEnabled = $ERCircuit.GlobalReachEnabled
$Data.ServiceKey = $ERCircuit.ServiceKey
$ERGREnabled += $Data
$GRDataFull += $GRData
}
}
$ERGREnabled #For summarized human readable data
#$GRDatafull #For the raw data if you want to hurt yourself.
<# Example Summarized Return
SubId : xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ERResourceGroup : naka
ERCircuitName : naka-er
GRName : naka-gr-to-zsoldier
GRAddressPrefix : ###.###.###.##/##
PeerERResourceGroup : zsoldier
PeerExpressRoute : zsoldier-er
PeerSubId : xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
SPName : Megaport
PeeringLocation : Las Vegas
Bandwidth : 1000
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.