-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-AzSubnetUdrConfig.ps1
More file actions
53 lines (33 loc) · 1.36 KB
/
Get-AzSubnetUdrConfig.ps1
File metadata and controls
53 lines (33 loc) · 1.36 KB
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
47
48
49
50
51
$subs = @( "subid"
)
foreach ($sub in $subs) {
$subscriptionName = (Get-AzSubscription -SubscriptionId $sub).Name
Write-Output "Setting context to $subscriptionName"
Set-AzContext -SubscriptionId $sub
$vNets = Get-AzVirtualNetwork
foreach ($vNet in $vNets) {
Write-Output "Getting subnet data from vNet - $($vNet.Name)"
$subnets = $vNet.subnets
foreach ($subnet in $subnets) {
Write-Output "Getting UDR data from subnet - $($subnet.Name)"
$vNetName = $subnet.Id.Split("/")[-3]
$subnetName = $subnet.Name
$routeTable = $subnet.RouteTable.Id
if ($null -ne $routeTable) {
$routeTable = $routeTable.Split("/")[-1]
}
else {
$routeTable = "Not Configured"
}
$obj = New-Object PSObject -Property @{
vNet = $vNetName
Subnet = $subnetName
Route_Table = $routeTable
Region = $vNet.Location
Subscription = $subscriptionName
}
## Change the path to a valid path on the system that you're running the script from
$obj | Select-Object vNet, Subnet, Route_Table, Region, Subscription | export-CSV 'C:\Temp\udrReport.csv' -Append
}
}
}