How to remove NICs with non-existent VMs still referenced

Kris Dawson 20 Reputation points
2025-05-09T14:52:14.45+00:00

We've got two NICs preventing us from deleting a virtual network, unfortunately we can't delete those NICs because they're referencing virtual machines that no longer exist. We've attempt to use CLI and Powershell commands to update the NICs to remove the VM references but that did not work either. How do we go about removing these NICs so we can remove the vnet?

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.


Answer accepted by question author
Alex Burlachenko 25,290 Reputation points MVP Volunteer Moderator
2025-05-14T07:40:15.24+00:00

Hi Kris,

Thank you for posting your question on the Q&A portal! Let’s try to resolve this step by step in a simple way.

First, it’s important to check if those network interface cards are still somehow linked to other resources or if there’s a delay in Azure’s system updating their status. You can verify the state of the network interface cards by running the following Azure CLI command:

az network nic show --ids <NIC_ID>  

If the output shows that the virtual machine reference is still there, even though the virtual machine is gone, you might need to force the removal of the reference. According to the Microsoft documentation, you can dissociate a network interface card from a virtual machine even if the virtual machine is deleted, but sometimes manual intervention is needed. Here’s the link to the official guide on managing network interfaces in Azure: Microsoft Docs - Manage network interfaces.

Another thing you can try is using Azure PowerShell to remove the virtual machine reference forcefully. Here’s a simple command that might help:

$nic = Get-AzNetworkInterface -Name <NIC_Name> -ResourceGroupName <ResourceGroup_Name>  
$nic.VirtualMachine = $null  
Set-AzNetworkInterface -NetworkInterface $nic  

After running this, wait a few minutes and check if the network interface card is now free from the virtual machine reference. If it still doesn’t work, sometimes deleting the network interface card directly through the Azure portal by navigating to the resource and selecting "Delete" can bypass the issue, as long as no other dependencies are blocking it.

If none of these steps work, it might be worth checking if there are any locks or policies preventing the deletion. You can review resource locks in the Azure portal under the "Locks" section of the resource group. More details on managing locks can be found here: Microsoft Docs - Manage resource locks.

Let me know if you still run into trouble.

Best regards,
Alex
P.S. If my answer help to you, please Accept my answer
PPS That is my Answer and not a Comment
https://ctrlaltdel.blog/

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Nikhil Duserla 9,950 Reputation points Microsoft External Staff Moderator
    2025-05-09T16:46:36.4566667+00:00

    Hello @Kris Dawson,

    To remove Network Interfaces (NICs) referencing non-existent virtual machines in Azure, start by checking for any dependencies associated with those NICs. If they still appear as 'in use,' ensure there are no remaining resources such as public IP addresses, network security groups, or load balancers linked to them.

    You can access Azure Cloud Shell directly from the Azure portal.

    First, list all the NICs in your subscription to identify the ones you want to delete- az network nic list --output table

    If you have identified the NICs that are not associated with any service, you can delete them using the following command- az network nic delete --name <NIC_NAME> --resource-group <RESOURCE_GROUP_NAME>

    After deletion, you can verify that the NICs are removed- az network nic list --output table

    Once the NICs are deleted, you can proceed to delete the virtual network- az network vnet delete --name <VNET_NAME> --resource-group <RESOURCE_GROUP_NAME>

    If you found this informative, please consider accepting an answer as a token of appreciation. And don't forget to give it a thumbs up 👍 if it was helpful.

    User's image

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.