Open In App

How to Delete Virtual Network in Azure

We often create virtual networks in Azure to manage and maintain our virtual machines. When the virtual machines or resources are no longer needed, we manage them by deleting the virtual machines, and sometimes we may also find the virtual network is no longer needed. We may find the VNET no longer needed considering the factors including resource usage, project lifecycle, and cost optimization. In this article, let us understand deleting a Virtual Network in Azure with different approaches. Before diving into the topic, let us have an overview of the Virtual network in Azure.

Azure Virtual Network allows its customers to create, manage, monitor, and secure connectivity between Azure resources and their on-premise environments.



Creating a Virtual Network using Azure PowerShell

To execute the desired action, kindly access Windows PowerShell and proceed by selecting “Run as administrator” from the context menu upon right-clicking.



Enter the following commands to create a Virtual Network using Azure PowerShell

Step 1: Set up the Azure services in PowerShell

As the initial step, establish the Azure services within PowerShell environment by executing the following command:

Install-Module Az -Force -AllowClobber

In addition, you may need to adjust the execution policy to ‘RemoteSigned’ by running the following command:

Set-ExecutionPolicy RemoteSigned

Step 2: Connect to your Azure account

To connect to your Azure account, Navigate to your azure portal and search for tenant properties, under that find the tenant Id. copy the tenant Id.

To establish a connection, kindly utilize the “Connect-AzAccount” command in PowerShell, specifying your Tenant ID as follows:

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

It will ask to choose your Azure account and after Authentication is completed, you can navigate back to the PowerShell.

Step 3: Create a Resource Group

Execute the following command in PowerShell to create a new resource group, ensuring to replace <your-resource-group-name> with your desired name and <your-resource-group-location> with the location of your resource group.

New-AzResourceGroup -ResourceGroupName <your-resource-group-name> -Location <your-resource-group-location>

Step 4: Create a Virtual Newtwork in the resource group

Establish a Virtual Network within the designated resource group by executing the following PowerShell command:

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

Ensure to replace placeholders such as <your-vnet-name>, <your-resource-group-name>, <your-resource-group-location>, and <address-prefix-of-your-vnet> with appropriate values as per your configuration.

Step 5: Check whether the Virtual Network is created or not

Verify the existence of the Virtual Network by executing the following command in the PowerShell environment.

Get-AzVirtualNetwork -Name myVnet001

Deleting a Virtual network using PowerShell

There are multiple ways to create or delete a virtual network. Either we can delete the virtual network from the Azure portal directly or We can use commands to delete the virtual network using the PowerShell. Let us see how to delete a virtual network using PowerShell.

Step 1: To remove the Virtual Network, please execute the following command in PowerShell.

Remove-AzVirtualNetwork -Name <your-vnet-name> -ResourceGroupName <your-resource-group-name>

Ensure that you replace <your-vnet-name> with the name of your Virtual Network and <your-resource-group-name> with the name of your resource group.

Step 2: Validate the deletion status of the virtual network by executing the following command.

Get-AzVirtualNetwork -Name myVnet001

Step 3: In the absence of a virtual network bearing the specified name, the system will display no results or information pertaining to it.

Step 4: In addition, you may navigate to the Azure portal and access the “Marketplace” section, followed by selecting “Virtual Networks” to verify the absence of any virtual network bearing the specified name.

To delete the Virtual network using Azure Portal, Navigate to the Virtual Networks service in the marketplace and Delete the associated Vnets and subnets using the Delete option.

Deleting a Virtual Network using Azure Portal

Here is the detail steps to delete the virtual network using the azure portal.

Step 1: Access Azure Portal

Step 2: Sign In

Step 3: Navigate to Virtual Network Section

Step 4: Explore Virtual Networks

Step 5: Select Virtual Network

Identify and select the specific virtual network that you intend to delete.

Step 6: Review Connected Resources

Step 7: Handle Connected Resources

Step 8: Initiate Virtual Network Deletion

Step 9: Start Deletion Process

Step 10: Confirm Deletion

Conclusion

Deleting Virtual Network can be cost-effective and resource optimisation when it is not longer required but, Ensure and back-up the underlying critical resources with the virtual network.

Delete Virtual Network in Azure – FAQs

Why would I want to delete a virtual network in Azure?

Any resource in Azure portal can be deleted if they are no longer needed.

Will deleting a virtual network affect other resources in my Azure environment?

Yes, deleting a virtual network in Azure will also delete the associated subnets, network security groups, and any connected virtual machines.

Can I undo the deletion of a virtual network in Azure?

No, deletion of a Virtual network in Azure is irreversible. This process can’t be undone.

Is there a way to automate the deletion of virtual networks in Azure?

Yes, You can automate the process of creation/deletion of virtual networks using pipelines or Azure Automation.

What precautions needed to be taken while deleting a Virtual network?

Follow the necessary precautions while deleting a virtual network

  • Ensure whether you have proper permissions to delete a Virtual network.
  • Check whether there are no critical resources depending on your Virtual network.
  • Backup necessary resources and data.

Article Tags :