Harness Azure CLI to Keep Your App Service Name

In this post we walk through the steps I used to delete and recreate an Azure App Service under a different App Service Plan using the Azure CLI so that I could keep the *.azurewebsites.net name for consistency.

Published on 23 March 2021


This worked for me.

It may not work for you.

Your mileage may vary.

You've been warned.

You run this at your own risk!


I had the requirement recently to move an app service from one app service plan to another. This doesn't feel like an edge use case however the Azure portal does not allow for you to initiate a move especially if you are moving from a Windows based app service plan to a Linux based one or at least that I could find. One option was to create a new app service under the new app service plan but it would have a new name (as they have to be unique across Azure) and I initially wanted the same name so it would continue to work before I setup a custom domain on it.

The next idea was if I get all the wizard steps filling in ready in one browser window and then delete the original in another window, then click create in the original window, I would be able to keep the name without anyone sneaking in and taking it. This felt very risky. Now I don't think anyone would be able to register the same named app service at the exact same time I was deleting mine but I didn't want to risk it.

This left me with investigating the Azure CLI and scripting the change. I was aware that you can perform the actions I required (delete and create of a web app) through the Azure CLI so this felt like the right approach to take.


I had a couple of base requirements I wanted to achieve with the app service move.

  1. Keep the name

  2. Move from a Windows based plan to a Linux based plan to keep costs down

  3. Move to a paid for plan to allow for custom domains.


The script I will show below assumes that the target App Service Plan has already been provisioned and you have the name. You will need your source/original resource group name and the target resource group name. For me they were different however I would expect this to work fine with the same named resource group.

It is also assumed that the Azure CLI is intalled on your computer which the scripts are being run.


Make a backup of your items you are moving. The script defined below WILL delete everything the current app service has deployed to it.

This is NOT a script which will move the app service, it will destroy it and create another with the same name in a different place.



First you need to log into your Azure account with the Azure CLI

az login

This will launch a browser window for you to authenticate with Azure.

Subscription Selection

The next step is you need to select your subscription. If you have only one then this will be selected automatically otherwise you will need to select the required subscription.

Note: I have not tried this across subscriptions. I'd imagine there will be more steps to do if going across subscriptions as well. Good luck!

az account set --subscription "Pay-As-You-Go"

In my case the subscription name was "Pay-As-You-Go".


It is now time to setup some variables for the script to use.

# original resource group
$Original_RG = "source-rg"

# Target rg
$Target_RG = "target-rg"

# Target app service plan
$Target_App_Service_Plan = "target-app-service-plan"

# name of app which is being re-created
$APP_NAME = "my-awesome-app"

The names of the variables should be self explainatory and these will be used throughout the rest of the script actions.

Delete Original App Service

The only way I could find to move an app service between plans was to delete and re-create it on the new app service plan. I couldn't find a way to move it through the portal but there maybe a way through the CLI. However I did not go for this route, deleting and re-creating was fine for my needs.

# DELETE the old one
az webapp delete `
    --name $APP_NAME `
    --resource-group $Original_RG 

First you delete the app from the original resource group. This is using the az webapp delete command. To delete an app I found you only needed the name and the resource group which it was defined in.

Create New App Service

Next is to create the app service on the target plan with the same name as before.

# Create the new one
az webapp create `
    --resource-group $Target_RG `
    --name $APP_NAME `
    --plan $Target_App_Service_Plan `
    --runtime '"DOTNET|5.0"'

This is done through the az webapp create command. It requires the target resource group, the name (which you wanted to keep in the first place!), the target app service plan and the target runtime.

The target runtime is important as this defines what framework your application is going to be running under. In the Azure portal this is driven by the "Runtime Stack" dropdwn in the creation wizard. The dropdown values relate to specific "enum" type values which you will need to determine for your specific scenario.

And that's it. I found in less than 20 seconds I had deleted my application and re-created it in the new plan and kept the name!


Once you have created the target app service in it's new home there will not be anything deployed to it as it is essentially "brand new". If you deploy your code through AzureDevOps, Github or another CI/CD pipeline you will need to update the variables, targets, resource groups, connections etc. as required and re-deploy your application.

If you manually deploy your website or application then you may want to investigate automation. It might sound scary but it makes life so much easier.


In this post we have run through the steps I used to move an app service from one app service plan to another in Azure while keeping the same name. It is something I will be looking to do for some other apps in the future which is why I am primarily documenting it here for personal use however I hope it helps others in the future as well.

Any questions/comments then please contact me on Twitter @WestDiscGolf