Create a Web App using Azure PowerShell

June 22, 2022
2 min read

The tools that the Azure Portal provides are great.  You can spin up an environment in just a few minutes.  However, sometimes you want to do it quicker.  Below is a PowerShell script I use to spin up an environment all in one ps1 file.


Create a text file and call it create-webapp.ps1.  Fill it in with the following:

# Define the environment
# tier of server, one of: Free,Basic,Shared,Standard,Premium,PremiumV2,PremiumV3,Isolated,IsolatedV2
# size of server, one of: small,medium,large

# Create a resource group.  
New-AzResourceGroup -Name $ResourceGroupName -Location $location  

# Create an App Service plan in Free tier.  
#New-AzAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlan -Location $location -Tier $tier -Linux

# Or, Create an App Service with a paid tier.
New-AzAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlan -Location $location -Tier $tier -Linux -NumberofWorkers $numworkers -WorkerSize $workersize

# Create a web app.   
New-AzWebApp -Name $webappname -Location $location -AppServicePlan $AppServicePlan -ResourceGroupName $ResourceGroupName  


That's it.  Now you can run the script and your environment will be setup in no time.  You can see how to setup your local PowerShell environment in my “Setting up Azure for PowerShell” post.


If you want to dump the new environment, you can simply run this command from PowerShell

#Dump the demo resource group and everything inside
Remove-AzResourceGroup -Name demo-resource-group -Force