Script to Help You to Create VNET


Hy Guys! Theres one script to help you to create one VNET.


I Use Azure Powershell to make this.


First, login on our environment




#Now, we use some variables:


#Name of the resource group you want to use to create VNet
# Name of the location where the resource group is located, or, it can also be another location. Ex: brazilsouth, eastus2, weastus
$loc = "location_name"
# Name of the Subnet you want to create. Note: In case, if you want to create a Gateway Subnet (which is used to close a VPN) you must specify here the following value: GatewaySubnet. Otherwise, you may choose to use any other name you want.
$subname1 = "subnet_name1"
# Range of IP to be used by Subnet. (E.g. & amp; amp; amp; amp; amp;
# Note: As we will first specify Subnet and then VNet, we must be aware that the subnet range is within the range of VNet.
# As well? We can not have a Vnet (254 addresses) and within it a Subnet (510 addresses).
$subipclass1 = "subclass_class1"
# Name of the Second Subnet you want to create. Note: If you wanted to create only one Subnet, it is possible. Just disregard this variable and the next.
$subname2 = "subnet_name2"
# Range of IP to be used by the Second Subnet. (E.g.
$subipclass2 = "class_of_ip_subnet2"


#Let's pass the command to create the 2 Subnets, for the variables $ subnet1 and $ subnet2:

#Note: This will be done to minimize VNet's build command. So optimizing our Script.


$subnet1 = New-AzureRmVirtualNetworkSubnetConfig -Name $subname1 -AddressPrefix $subipclass1

$subnet2 = New-AzureRmVirtualNetworkSubnetConfig -Name $subname2 -AddressPrefixn $subipclass2


# We will now store in 2 variables the name of VNet and the IP Class to be used by it


$vnet = "VnetName"
$vnetipclass = "class_ip_vnet"


# Finally, now let's create VNet, already with the 2 Subnets informed and the entire network environment already defined. (Subnets, VNet and IP Class)


New-AzureRmVirtualNetwork -Name $vnet -ResourceGroupName $rg -Location $loc -AddressPrefix $vnetipclass -Subnet $subnet1,$subnet2


And ready! Our VNet has already been created, and is now available on Azure for use.

Simple? Easy? Fast? (Leave your feedback!)


I hope you enjoy!


Big Hug!

0 Replies