Provision WebApp to a AppServiceEnvironment with Powershell

If you deploy your WebApps today to Azure using web deploy and the ServiceManagement API (ASM) and you need to move WebApp to the AppServiceEnvironment (ASE) you are faced with the reality that the New-AzureWebsite powershell cmdlet do not support that. You need to add just a little bit of ResourceManager API (ARM) in the right place and you can continue to use the ServiceManagement APIs and avoid the big rewrite of your provisioning scripts.

How much needs to change?

The ServiceManagement cmdlets Get-AzureWebsite, New-AzureWebsite and Set-AzureWebsite work perfectly against a WebApp once it is created in the AppServiceEnvironment. So in theory, existing provisioning code that uses the web deploy technique can continue to work once the WebApp is AddApp_Portalcreated in the ASE. However, that model means that provisioning will be partly manual which becomes a burden if you have 20+ WebApps that should be deployed. So the only thing that needs to change is to find a new method to replace the call to powershell New-AzureWebsite, since that cmdlet only provisions the WebApp in the Free/Shared/Basic/Standard Hosting Plan. We need to find a way to do what the “Add App” function do in the portal.

Resource Group Template

In order to solve this we need a Resource Group Template json file which we can create in Visual Studio via creating a new Cloud project of type “Azure Resource Group”.


In that project you get a file named WebSite.json which you need to modify the following way:

  1. Add a “hostingEnvironment” parameter under parameters
  2. Add a “hostingEnvironment” under resources/properties
  3. Remove everything in the json file after “type” : “Microsoft.Web/sites” to keep the file minimalistic



Provisioning script – putting it all together

We can now change the script that provisions the WebApp to use the template and create the WebApp in the ASE if it doesn’t exist. It would look something like below. If the website do not exist we need to create it, but if it should be deployed in an AppServiceEnvironment, then we switch to ResourceManager APIs, invoke the New-AzureResourceGroup passing the json template we created.


There is one more thing you need to make sure you do and that is to use the correct url to deploy the web deployment package (zipfile). An AppServiceEnvironment do not use the url but the xxxxxx.scm.yyyyyy.p.azureweb, where xxxxxx is the name of the WebApp and yyyyyy is the ASE name. If you get the url from the property EnabledHostNames and look for the url that includes “.scm.” it will work, regardless if it’s an ASE hosted WebApp or not.



By just creating the json resource template file in Visual Studio, adding a few lines of code, and modifying the provisioning powershell script at one place, you can target AppServiceEnvironment as the hosting environment for your WebApps. Yes, you probably should start planning for the migration of your provisioning scripts to use ARM but using what I showed you here, you can leave that to the future for a while – Great Scott!