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 the Script
Create a text file and call it create-webapp.ps1. Fill it in with the following:
# Define the environment $ResourceGroupName="demo-resource-group" $AppServicePlan="demo-mysuper-linux-plan" $webappname="demo-mysuper-website" $location="WestUs" # tier of server, one of: Free,Basic,Shared,Standard,Premium,PremiumV2,PremiumV3,Isolated,IsolatedV2 $tier="PremiumV2" $numworkers=1 # size of server, one of: small,medium,large $workersize="small" # 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