-
Notifications
You must be signed in to change notification settings - Fork 0
/
List-AllAzSubnets.ps1
82 lines (67 loc) · 2.32 KB
/
List-AllAzSubnets.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<#
.Synopsis
List All Subnets in a Subscription along with SubnetPrefix,SubnetNSG,VNET,Location,UDR,ResourceGroup,Subscription,DDoS.
.Description
List All Subnets in a Subscription along with SubnetPrefix,SubnetNSG,VNET,Location,UDR,ResourceGroup,Subscription,DDoS.
.Parameter Port
None.
.Example
#List All NSGs along with the Security Rules for a Subscription.
List-AllAzSubnets
#>
#------------------------------------------------------------------------------
#
#
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
#
#------------------------------------------------------------------------------
$vnet1 = $null
$vnet1 = Get-AzVirtualNetwork
$outtest = @()
$c = $vnet1.Subnets.id.Count
$subnet1 = @()
$rg1 = @()
$vnetname = @()
$subid = @()
$subpre = @()
$SubnetNSG = @()
$loc = @()
$DDoS = @()
$UDR = @()
if($c -eq 1){$vnet1}
Else{
For($i=0; $i -lt $c; $i++){
$subnet1 += $vnet1.Subnets.id[$i].Split("/")[10]
$rg1 += $vnet1.Subnets.id[$i].Split("/")[4]
$vnetname += $vnet1.Subnets.id[$i].Split("/")[8]
$subid += $vnet1.Subnets.id[$i].Split("/")[2]
$subpre += $vnet1.subnets[$i].AddressPrefix
#VNET Specfic Details
$vnetsubspecific = Get-AzVirtualNetwork -Name $vnetname[$i] -ResourceGroupName $rg1[$i]
$loc += $vnetsubspecific.Location
$DDoS += $vnetsubspecific.DdosProtectionPlan
#
# line for possible null values in Subnet
$SubnetNSG += $vnet1.Subnets[$i].NetworkSecurityGroup.Id | ForEach-Object{$_ -replace ".*/"} #.Split("/")[8]
$UDR += $vnet1.Subnets[$i].RouteTable.id | ForEach-Object{$_ -replace ".*/"}
# Custom object
$outtest += New-Object PSObject -Property @{
Subnet = $subnet1[$i]
Subscription = $subid[$i]
Resourcegroup = $rg1[$i]
Vnet = $vnetname[$i]
Subnetprefix = $subpre[$i]
VNETLocation = $loc[$i]
DDoS = $DDoS[$i]
SubnetNSG = $SubnetNSG[$i]
UDR = $UDR[$i]
}
}
Write-Warning "All attributes are specfic to Subnet only."
$outtest | FT -Property Subnet,SubnetPrefix,SubnetNSG,VNET,Location,UDR,ResourceGroup,Subscription,DDoS
Write-Warning "All attributes are specfic to Subnet only."
}