Share via

Unable to delete a resource group and associate subnet

Iain Segall 20 Reputation points
2026-02-07T19:04:22.15+00:00

I have an old set of resources I am trying to remove. The associated SAAS service has been removed

I have manually used commands such as:

Remove-AzVirtualNetwork -Name "PII" -ResourceGroupName "PII" -Force

Remove-AzVirtualNetwork: Subnet PII is in use by /subscriptions/PII/resourceGroups/PII/providers/Microsoft.Network/virtualNetworks/PII/subnets/PII/serviceAssociationLinks/AppServiceLink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

StatusCode: 400

ReasonPhrase: Bad Request

ErrorCode: InUseSubnetCannotBeDeleted

ErrorMessage: Subnet PII is in use by /subscriptions/PII/resourceGroups/PII/providers/Microsoft.Network/virtualNetworks/PII/subnets/snet-scepman-appservices/serviceAssociationLinks/AppServiceLink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.

OperationID : PII

On trying to delete subnet, Remove application links I get similar errors.

It looks like there is still an orphaned resource remaining

Is there a way to force a deletion?

Azure Virtual Network
Azure Virtual Network

An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.

{count} votes

Answer accepted by question author
  1. TP 152.1K Reputation points Volunteer Moderator
    2026-02-08T03:12:14.6566667+00:00

    Hi Iain,

    Please run command similar to below in Azure Cloud Shell (Bash mode) to purge unused Service Association Link (SAL). Substitute SubscriptionId, Location, SubnetId. Subnet Id can be found by navigating to your subnet in portal and clicking the Copy icon next to Subnet ID

    az rest --method POST \
         --uri "/subscriptions/<SubscriptionId>/providers/Microsoft.Web/locations/<Location>/purgeUnusedVirtualNetworkIntegration?api-version=2024-04-01" \
         --body "{'subnetResourceId': '<SubnetId>'}"
    
    

    You should see output similar to below:

    User's image

    Once you have completed the above, try the delete again.

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Nikhil Duserla 9,685 Reputation points Microsoft External Staff Moderator
    2026-02-07T19:34:50.2566667+00:00

    Hello @Iain Segall ,

    It sounds like you’re having a tough time getting rid of that resource group and subnet due to some lingering resources. Here's what you can try to resolve the issue:

    Identify Resources: Start by identifying any resources that might still be using the subnet. The error message you received indicates that there's a service association link related to an App Service. Here are a couple of steps you can follow:

    • Check if there's still an App Service linked to the virtual network. If the App Service is still present, disconnect it from the VNet under App Service > Networking > VNet integration.
      • If the App Service has been deleted, you might need to recreate it briefly to disconnect the VNet before deletions.
      Delete Orphaned Resources: If there are any orphaned resources preventing deletion, you can attempt to locate and delete the service association link using the Azure CLI. Use the following command to retrieve the network profile ID:
        NetworkProfile=az network vnet subnet show -g <YourResourceGroup> --vnet-name <YourVNetName> --name <YourSubnetName> -o tsv --query ipConfigurationProfiles[].id
      
      After retrieving the NetworkProfile, run this command to delete it:
        az network profile delete --ids $NetworkProfile --yes
      
      Final Cleanup: Afterwards, try deleting the subnet again:
        az network vnet subnet delete --resource-group <YourResourceGroup> --vnet-name <YourVNetName> --name <YourSubnetName>
      
      If successful, you can then proceed to delete the virtual network and the resource group. Double-Check Resources: If that doesn't work or if you encounter similar errors, verify there are no additional dependencies:
        - Check for any Virtual Machines, Gateways, or Application Gateways that could be using the VNet.
        
        
           - Ensure there's no IP configuration or Container Instances tied to the subnet.
        
           
           **Use the Azure Portal**: In the Azure portal, you can also click on the resource group → Overview page, and then click on **Show hidden types** to check for hidden network profiles that might need to be deleted.
        ```Hope this helps! Let me know if you run into any issues while trying these steps.
      
      

    References:

    Let me know if you need any further assistance!

    Was this 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.