Azure: Deploy a WebApp with PowerShell

A quick run through using PowerShell to deploy a new WebApp. ASP.NET code for the website has been zipped up (into and this code snippet will upload it to a new WebApp, hosted in a new App Service Plan and a new Resource Group.

From a local PowerShell session use Connect-AZAccount before running this code to sign-in to Azure. Alternatively this code can be run (with the exception of the upload itself) from the Cloud Shell directly in the Azure Portal.

The code also writes out the URL of the resulting WebApp and the PowerShell necessary to tear down the resources when they are no longer required.

 1#Set some parameters
 2$location="UK South"
 3$resourceGroupName= "rsg-myapp"
 8#Create Resource Group
 9"-- Creating Resource Group"
10New-AzResourceGroup -Location $location -Name $resourceGroupName 
12#Create ServicePlan
13"-- Creating Service Plan"
14New-AzAppServicePlan -ResourceGroupName $resourceGroupName -Name $appServicePlanName -Location $location -Tier Free
16#Create Web App
17"-- Creating Web App"
18New-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName -Location $location -AppServicePlan $appServicePlanName
20#Upload the web code
21"-- Uploading Web App Code"
22Publish-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName -ArchivePath $codeZIPPath –Force
24#Show user code to destroy this (useful for testing)
25# and the website that has been created.
26"-- Tidy Up Code: "
27" Remove-AzResourceGroup -Name $resourceGroupName"
28"-- Website: "
29"-- https://$"
31"-- Done"

The resulting website can be viewed just by pointing a browser at the given URL. The created resources can be checked in the Azure portal: