-
Notifications
You must be signed in to change notification settings - Fork 19
/
Create_VNet_with_Az_PowerShell.ps1
46 lines (32 loc) · 1.25 KB
/
Create_VNet_with_Az_PowerShell.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
az login
az account show
az account list --all --output table
az account set --subscription "your subscription name"
#Create a resource group
az group create --name myResourceGroup --location westeurope
#Create virtual networks
az network vnet create --name myVirtualNetwork1 --resource-group myResourceGroup --address-prefixes 10.0.0.0/16 --subnet-name Subnet1 --subnet-prefix 10.0.0.0/24
#The PowerShell way
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "your subscription name" | Select-AzSubscription
Get-AzContext
#Create a resource group
New-AzResourceGroup -ResourceGroupName myResourceGroup2020 -Location WestEurope
#Create a virtual network
$virtualNetwork1 = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroup2020 `
-Location WestEurope `
-Name myVirtualNetwork1 `
-AddressPrefix 10.1.0.0/16
#Create a subnet configuration
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
-Name Subnet1 `
-AddressPrefix 10.1.0.0/24 `
-VirtualNetwork $virtualNetwork1
#Write the subnet configuration to the virtual network
$virtualNetwork1 | Set-AzVirtualNetwork