How to create Virtual Network in Azure using PowerShell?

Configurare noua (How To)

Situatie

Microsoft Azure provides various resources and services to provide us with a scalable environment for development and testing processes. Azure provides a virtual machine service, which allows us to leverage the resources virtually. We may have more than one virtual machine as a resource, according to our requirements. To manage and monitor our virtual machines, Microsoft Azure provides a service called Virtual Network.

Solutie

Pasi de urmat

Setting up Azure PowerShell

  • Locate the Windows PowerShell application on your system
  • Right-click on the Windows PowerShell icon
  • From the context menu, select “Run as Administrator”
  • If prompted by User Account Control (UAC), click “Yes” to confirm
  • The Windows PowerShell window will open with elevated privileges, allowing you to perform administrative tasks.

Now, enter the following commands to install all the necessary packages required to set up Azure. Below command installs all the modules of Azure services.

Install-Module Az

Now, enter the following command to check whether you are an Authorized user or not

Get-ExecutionPolicy

If the above command returns as ‘Restricted‘, You need to modify some rules to get access to Azure services.

Set-ExecutionPolicy RemoteSigned

Connect to your Azure Account

  • Navigate to the Azure portal and Find ‘tenant properties‘. Copy the Tenant ID.
  • Now, enter the following command to connect to your Azure account.

Connect-AzAccount -TenantId <Copy-your-tenantid-here>

This command prompts up and asks for the login credentials of your account once confirmed. You can navigate back to the PowerShell terminal.

Create a Virtual Network

Before creating a Virtual Network, let us create a Resource group to store the Virtual Network.

  • Creation of Resource Group: Enter the following command to create your resource group
  • New-AzResourceGroup -ResourceGroupName <your-resource-group-name> -Location <your-resource-group-location>
  • New-AzResourceGroup: This is the command we need to specify inorder to create a resource group in azure.
  • ResourceGroupName: This parameter specifies the name of the Resource group
  • Location: This Paramter specifies the location of the resource group

Now, enter the following command to create a virtual network in the resource group you created.

$<your-vnet-name> = New-AzVirtualNetwork -ResourceGroupName <your-resourcegroup-name> -Location <your-resource-group-location> -Name <yTour-vnet-name> -AddressPrefix <address-prefix-of-your-vnet>

  • New-AzVirtualNetwork: This command is used to create a new virtual network in the specified resource group.
  • ResourceGroupName: This parameter specifies the name of the resource group
  • Location: This parameter specifies the location of the resource
  • Name: This parameter specifies the name of the virtual network

To check whether, the virtual network is created or not, enter the following command.

Get-AzVirtualNetwork -Name myVnet001

Deploying the Virtual Network in Azure Bastion

Azure Bastion acts as a jump server or bastion host, providing a secure gateway to access virtual machines in Azure virtual networks.It eliminates the need to expose virtual machines to the public internet, reducing the surface area for potential attacks.

New-AzBastion -ResourceGroupName $resourceGroupName -Name $bastionName -VirtualNetwork $vnet

Tip solutie

Permanent

Voteaza

(2 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?