-
Notifications
You must be signed in to change notification settings - Fork 7
/
ARM - Virtual Network (VNet).ps1
125 lines (69 loc) · 3.03 KB
/
ARM - Virtual Network (VNet).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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<# Virtual Network (VNet) #>
<#
#>
# Variables - Virtual Network
$vnetShortName = "qweasdzxc"
$vnetSuffix = "-vnet"
$vnetName = "${vnetShortName}${vnetSuffix}"
# subnets
$webSubnetName = "WebSubnet"
$frontendSubnetName = "FrontEndSubnet"
$backendSubnetName = "BackEndSubnet"
<# Create Virtual Network (VNet), if it does not exist #>
Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -ErrorVariable isVNetExist -ErrorAction SilentlyContinue `
If ($isVNetExist)
{
Write-Output "Virtual Network does not exist"
Write-Verbose "Creating new subnet: {$webSubnetName}"
$webSubnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name $webSubnetName `
-AddressPrefix "10.0.0.0/24"
Write-Verbose "Creating new subnet: {$frontendSubnetName}"
$frontendSubnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name $frontendSubnetName `
-AddressPrefix "10.0.1.0/24"
Write-Verbose "Creating new subnet: {$backendSubnetName}"
$backendSubnet = New-AzureRmVirtualNetworkSubnetConfig `
-Name $backendSubnetName `
-AddressPrefix "10.0.2.0/24"
Write-Verbose "Creating new Virtual Network: {$vnetName}"
$vnet = New-AzureRmVirtualNetwork `
-Name $vnetName `
-ResourceGroupName $rgName `
-Location $location `
-AddressPrefix 10.0.0.0/16 `
-Subnet $webSubnet, $frontendSubnet, $backendSubnet `
-Tag $tags
}
Else
{
Write-Output "Virtual Network exist"
Write-Verbose "Fetching Virtual Network: {$vnetName}"
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName
}
Write-Verbose "Get list of all Virtual Network (VNet)"
Write-Output "Virtual Networks (VNet)"
Get-AzureRmVirtualNetwork -ResourceGroupName $rgName `
| Select-Object Name, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap
<#
Get-AzureRmVirtualNetwork `
| Select-Object Name, ResourceGroupName, Location `
| Format-Table -AutoSize -Wrap -GroupBy ResourceGroupName
#>
<#
## Remove Virtual Network (VNet)
$vnetShortName = "qweasdzxc"
$vnetSuffix = "-vent"
$vnetName = "${vnetShortName}${vnetSuffix}"
Write-Verbose "Deleting Virtual Network (VNet): {$vnetName}"
Remove-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Force
#>
<#
## References
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-virtual-network
https://docs.microsoft.com/en-us/azure/virtual-network/quick-create-powershell
https://docs.microsoft.com/en-us/powershell/module/azurerm.network/get-azurermvirtualnetwork?view=azurermps-6.13.0
https://github.com/robotechredmond/Azure-PowerShell-Snippets/blob/master/Azure%20Resource%20Manager%20-%20Create%20V2%20environment%20w%20VNET%20GW%20demo.ps1
https://docs.microsoft.com/en-us/powershell/module/azurerm.network/add-azurermvirtualnetworksubnetconfig?view=azurermps-6.13.0
#>