Answered by:
Unable To Remove Azure Route Table

Question
-
Hello,
We currently have a customer (@RaymondJDevine) who engaged our team on Twitter. They are having an issue with removing an Azure route table. When they try and remove the route table, they are getting an error message that says it is in use.
They have tried the following steps with no resolution
1. Tried using the azuresubnetroutetable commands to remove it but is presented with a "resourcenotfound" message.
2. They stopped all of their VMs on the subnet
3. They shutdown the cloud service and restarted
4. They restarted the host that executed the command on. It does have the Azure cmdlets installed locally.Do you have any suggestions for this use that would resolve their issue?
@AzureSupport
Thursday, February 25, 2016 11:37 PM
Answers
-
Hi Raymond,
I'm sorry about your experience with route tables. If Remove-AzureRouteTable gave a more detailed error about the existing association, it could have made things simpler.
The script above was supposed to indicate the virtual network & the subnet to which your route table is attached.
The command Remove-AzureSubnetRouteTable is to remove any route table that is attached to the given virtual network and subnet.
So, the second command you provide is accurate based on the output from the script.
Route table Subnet-2 assigned to vnet:CloudSub, subnet:Subnet-1
Remove-AzureSubnetRouteTable -VirtualNetworkName “CloudSub” -SubnetName Subnet-1 (//Remove the subnet attached to vnet:CloudSub, subnet:Subnet-1)
Thanks!
- Edited by Siva Edupuganti Tuesday, March 1, 2016 11:21 PM
- Marked as answer by Viorica NorthcuttMicrosoft employee Wednesday, March 2, 2016 6:20 PM
Tuesday, March 1, 2016 11:20 PM
All replies
-
I tried remove-azureroutetable first. It worked removing one of the two I had, but the first one I created, I cannot remove.
PS C:\Windows\system32> remove-azureroutetable
cmdlet Remove-AzureRouteTable at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Name: subnet-2Confirm
Are you sure you want to remove the Route Table "subnet-2"?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
remove-azureroutetable : BadRequest : The Route Table subnet-2 is currently in
use.
At line:1 char:1
+ remove-azureroutetable
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureRouteTable], CloudE
xception
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagemen
t.Network.Routes.RemoveAzureRouteTablePS C:\Windows\system32>
Thursday, February 25, 2016 11:48 PM -
Using the -force switch has no effect.Thursday, February 25, 2016 11:48 PM
-
Hi,
"Currently in use" error indicates the route is assigned to a subnet.
Below is a simple powershell snippet to find the vnet & subnet a route table is assigned:
$rtname = "<name of the route table>" $vnets = Get-AzureVNetSite foreach ($vnet in $vnets) { #Write-Host "Checking subnets in ", $vnet.Name foreach ($subnet in $vnet.Subnets) { #Write-Host "Checking route tables assigned to ", $vnet.Name, $subnet.Name $rt = Get-AzureSubnetRouteTable -VirtualNetworkName $vnet.Name -SubnetName $subnet.Name -ErrorAction Ignore if ($rt -and $rt.Name -eq $rtname) { Write-Host ("Route table {0} assigned to vnet:{1}, subnet:{2}" -f $rtname, $vnet.Name, $subnet.Name) } } }
Once you find the vnet & subnet, you can remove the route table with following command:
Remove-AzureSubnetRouteTable -VirtualNetworkName $vnet -SubnetName $subnet
Thanks
- Edited by Siva Edupuganti Monday, February 29, 2016 3:59 PM
- Proposed as answer by Siva Edupuganti Wednesday, March 2, 2016 2:54 PM
Monday, February 29, 2016 3:57 PM -
Thanks for the help, with that query I was able to see that the route table was bound to another subnet as well. I tried to remove it again and at first it failed. In desperation I used the other subnet and that allowed me to remove the subnet.
Here is the output of the query:
Route table Subnet-2 assigned to vnet:CloudSub, subnet:Subnet-1
I could NOT delete Subnet-2 using this syntax:
Remove-AzureSubnetRouteTable -VirtualNetworkName “CloudSub” -SubnetName Subnet-2
Got the same Badrequest: Subnet in use error.
When I changed the command to:
Remove-AzureSubnetRouteTable -VirtualNetworkName “CloudSub” -SubnetName Subnet-1
That worked, and it removed the route table "Subnet-2".
I'm just glad it's gone, but honestly, what a mess.
Raymond J. Devine Cloud/Solutions Architect
Tuesday, March 1, 2016 10:58 PM -
Hi Raymond,
I'm sorry about your experience with route tables. If Remove-AzureRouteTable gave a more detailed error about the existing association, it could have made things simpler.
The script above was supposed to indicate the virtual network & the subnet to which your route table is attached.
The command Remove-AzureSubnetRouteTable is to remove any route table that is attached to the given virtual network and subnet.
So, the second command you provide is accurate based on the output from the script.
Route table Subnet-2 assigned to vnet:CloudSub, subnet:Subnet-1
Remove-AzureSubnetRouteTable -VirtualNetworkName “CloudSub” -SubnetName Subnet-1 (//Remove the subnet attached to vnet:CloudSub, subnet:Subnet-1)
Thanks!
- Edited by Siva Edupuganti Tuesday, March 1, 2016 11:21 PM
- Marked as answer by Viorica NorthcuttMicrosoft employee Wednesday, March 2, 2016 6:20 PM
Tuesday, March 1, 2016 11:20 PM