How to detach network interface from deleted vm Azure?

Cristóbal Cea 0 Reputation points
2024-11-25T15:16:45.9433333+00:00

I am trying to delete a Network Interface (NIC) in Azure that was previously associated with a Virtual Machine (VM). However, I am receiving an error stating that the NIC cannot be deleted because it is still associated with the VM, even though the VM has already been deleted.

When attempting to delete the NIC from the Azure portal, I am unable to proceed, and it prompts me to first detach it from the VM. Since the VM no longer exists, I am unsure how to disassociate the NIC from the non-existent VM.

I have checked for other dependencies that may be linked to the NIC (like Network Security Groups or Load Balancers) but haven't found any.

Could someone suggest the best approach to resolve this issue? Are there any PowerShell or CLI commands that can help disassociate the NIC from the deleted VM and allow me to delete it?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,093 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. anashetty 905 Reputation points Microsoft Vendor
    2024-11-25T17:52:04.4633333+00:00

    Hi Cristóbal Cea,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    We understand from your query that you are experiencing an issue while trying to delete Network Interface. I have I have tried from my end and shared troubleshooting steps:Open Azure Cloud shell and try below commands:

    List all resources in Resource group: az resource list --resource-group <ResourceGroup> --output table

    List all NICs in the Resource group: az network nic list --resource-group <ResourceGroup> --output table

    Try this command first to delete NIC: az network nic delete --resource-group <RESOURCE_GROUP> --name <yourtNIC>

    If the error shows again, try below steps:

    Check the NICs properties: az network nic show --name <your_NIC> --resource-group <RESOURCE_GROUP> Confirm the virtual Machine property still points to the deleted VM.

    Disassociate the NIC from Virtual Machine: az network nic update --name <your_NIC> --resource-group <RESOURCE_GROUP> --remove virtualMachine

    Now try deleting NIC: az network nic delete --resource-group <RESOURCE_GROUP> --name <your_NIC>

    If you still find any difficulties, please let me know I would like to work closer on this issue. If the answer is helpful, please click "Accept Answer" and "Upvote it" as it can be helpful to others in the community.User's image


Your answer

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