-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-VNETPeerings.ps1
46 lines (41 loc) · 2.09 KB
/
Get-VNETPeerings.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$Subs = Get-AzSubscription
$OutputList = @()
try {
Foreach ($Sub in $Subs) {
Set-AzContext -Subscription $Sub.id *>$null
$VNETs = Get-AzVirtualNetwork
foreach ($VNET in $VNETs) {
$VNETName = $VNET.Name
$VNETRG = $VNET.ResourceGroupName
$VNETSub = $Sub.Name
$DNSServers = ($VNET.DhcpOptionsText | ConvertFrom-Json).DnsServers -Join ", "
$AddressSpaces = ($VNET.AddressSpaceText | ConvertFrom-Json).AddressPrefixes -Join ","
$VNETLocation = $VNET.Location
$Peers = ($VNET.VirtualNetworkPeeringsText | ConvertFrom-Json)
ForEach ($Peer in $Peers) {
$PeeringName = $Peer.Name
$PeeringRemote = $Peer.RemoteVirtualNetwork
ForEach ($PeeRemote in $PeeringRemote) {
$Peee = ($PeeRemote -split("/"))[-1] -replace("}","")
$SubnetData = New-Object -Type PSObject
$SubnetData | Add-Member -Name 'VNETName' -Type NoteProperty -Value $VNETName
#$SubnetData | Add-Member -Name 'VNETRG' -Type NoteProperty -Value $VNETRG
#$SubnetData | Add-Member -Name 'VNETSub' -Type NoteProperty -Value $VNETSub
#$SubnetData | Add-Member -Name 'VNETPrefix' -Type NoteProperty -Value $AddressSpaces
#$SubnetData | Add-Member -Name 'DNSServers' -Type NoteProperty -Value "$DNSServers"
$SubnetData | Add-Member -Name 'Location' -Type NoteProperty -Value "$VNETLocation"
$SubnetData | Add-Member -Name 'PeeringName' -Type NoteProperty -Value $PeeringName
$SubnetData | Add-Member -Name 'PeeringRemote' -Type NoteProperty -Value $Peee
$OutputList += $SubnetData
}
}
}
}
}
catch
{
Write-Error -Message $_.Exception
throw $_.Exception
}
$OutputList | Export-Csv -Path VNETPeers.csv -NoTypeInformation
$OutputList | ogv