Creating VNet In Microsoft Azure Using PowerShell

In this article, you will learn about creating VNet in Microsoft Azure, using PowerShell.

Introduction

This article will help you to understand what Virtual Network is in Azure and how to create VNet in Azure, using Powershell.

Virtual Network

Microsoft’s Azure Virtual Network in short names such as VNet is a networking mode in Cloud. It’s a representation of a network that we have in Cloud. It helps to provision your Data Center, Azure network settings, DNS settings, routing and other DHCP address blocks. It also helps you to extend your own network to Azure, using IP address blocks.

Note

Read in detail about Azure VNet over here.

You can create VNet in Azure in two ways, using Azure portal or by PowerShell.

Technical Requirements

  1. Microsoft Azure account – Click here to get a free temporary Azure account.
  2. Windows PowerShell for Windows 10 – Click here to download it.

Follow the steps, mentioned below.

Step 1

Run your PowerShell now and login with your Azure account over here, using the command, mentioned below.

Login-AzureRmAccount

vnet

Login with your Azure account here.

vnet

There goes your account logged in.

Step 2

Now, create a resource group in your Azure account, using the command, mentioned below.
New-AzureRmResourceGroup -Name ________ -Location ___________

Note

In the command, mentioned below, replace the name “______” with the resource group name that you need and location “_________” with the location of Azure Data center that you prefer.

vnet

Now, Azure resource group is created with the name that we have mentioned.

Step 3

Lets create a new VNet now with the command, mentioned below.

New-AzureRmVirtualNetwork -ResourceGroupName vnetrg -Name TestVNet `-AddressPrefix 192.168.0.0/16 -Location centralus

vnet

You should get a display, as shown above.

Step 4

Let's store the virtual network object in a variable, using the command, mentioned below.

$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName TestRG -Name TestVNet

Step 5

Now, we will be adding a subnet to the VNet variable, using the command, mentioned below.

Add-AzureRmVirtualNetworkSubnetConfig -Name FrontEnd ` -VirtualNetwork $vnet -AddressPrefix 192.168.1.0/24

vnet

Step 6

Finally, you can save all the changes that you have done, using the command, mentioned below.

Set-AzureRmVirtualNetwork -VirtualNetwork $vnet

vnet

Follow my next article to work on a virtual network by creating a Virtual Machine, which will run a Windows VM, by selecting an existing VNet and subnet to connect a virtual machine.