Open In App

How to Delete Virtual Network in Azure

Last Updated : 26 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Powershell

Windows Power Shell

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

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.

Connect to your Azure account

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.

Authentication is completed

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

Check whether the Virtual Network is created or not

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.

remove the Virtual Network

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.

No Vertual Networks

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.

Deleted Virtual Networks

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

  • Open your web browser and navigate to the Azure Portal by typing in the URL or searching for “Azure Portal” in a search engine.

Step 2: Sign In

  • Sign in to the Azure Portal using your Azure account credentials. If you don’t have an account, you will need to create one.

Step 3: Navigate to Virtual Network Section

  • Once logged in, you’ll land on the Azure Portal dashboard.
  • Look for the navigation menu on the left-hand side of the screen.
  • Scroll down or use the search bar to find the “Virtual networks” option under the “Networking” category. Click on it to access the Virtual Network section.

Step 4: Explore Virtual Networks

  • In the Virtual Network section, you will see a list of virtual networks that have been created in your Azure account. You can click on each virtual network to view its details, settings, and associated resources.

Explore Virtual Networks

Step 5: Select Virtual Network

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

Select Virtual Network

Step 6: Review Connected Resources

  • Before proceeding with the deletion, carefully review if there are any connected devices or resources linked to the virtual network.

Review Connected Resources

Step 7: Handle Connected Resources

  • If there are connected resources:
    • Determine if they need to be backed up or migrated to another location.
    • Disconnect or delete the associated resources from the virtual network.

Step 8: Initiate Virtual Network Deletion

  • Return to the overview page of the virtual network.

Step 9: Start Deletion Process

  • Look for the “Delete” option and click on it to initiate the deletion process.

Start Deletion Process

Step 10: Confirm Deletion

  • Confirm the deletion action when prompted by the Azure portal.

Confirm Deletion

Confirm Deletion

  • Then you can navigate back to your virtual network and delete the Virtual network.

Vnet Deleted

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.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads