Using Azure PowerShell Commands To Create An App Service Web App

Azure PowerShell provides a set of cmdlets that use the Azure Resource Manager model for managing your Azure resources. You can use it in your browser with Azure Cloud Shell, or you can install it on your local machine and use it in any PowerShell session.

Azure PowerShell


Azure PowerShell provides a set of cmdlets that use the Azure Resource Manager model for managing your Azure resources. You can use it in your browser with Azure Cloud Shell, or you can install it on your local machine and use it in any PowerShell session. Use the Cloud Shell to run the Azure PowerShell in your browser, or install it on own computer.

Creating a Web App with Azure PowerShell

 
Creating an Azure Services Web App with Azure PowerShell follows a consistent pattern, 
  1. Create a basic MVC Web App
  2. Create the resource group
  3. Create the App Service Plan
  4. Create a web app
  5. Deploy the app
First, we need to create a simple web application for deployment purpose.
 
From visual studio select File > New > Project > Web > ASP.NET Core Web Aplication.
 
Set Project Name and click OK.
  
Using Azure PowerShell Commands To Create An App Service Web App
 
Select Web Application Template and click OK.
 
Using Azure PowerShell Commands To Create An App Service Web App

Next, build the project.

Using Azure PowerShell Commands To Create An App Service Web App

Then, right click on the project and select "Publish".

 Using Azure PowerShell Commands To Create An App Service Web App
 
Select the destination and choose a target folder that will contain all publisher files.
Using Azure PowerShell Commands To Create An App Service Web App
 
Once deployed locally, navigate to the location where you stored the local deployment, select all, and zip them up.
 
Using Azure PowerShell Commands To Create An App Service Web App
 
Using Azure PowerShell Commands To Create An App Service Web App
 
Next, we need to write a PowerShell script to deploy on to Azure.
 
Go to Azure Portal https://portal.azure.com and from the top bar, click on Cloud Shell.
 
Using Azure PowerShell Commands To Create An App Service Web App
 
Azure Cloud Shell requires an Azure file share to persist files. So, we will create a new storage account for that. Select your subscription and click on "Create Storage" button.
 
Using Azure PowerShell Commands To Create An App Service Web App
 
From upload/download files, we need to upload the WebApplicationDemo.deps.zip that be created in the previous steps. 
 
Using Azure PowerShell Commands To Create An App Service Web App
 
Then, type the below script. This is the script for creating a web app, and for deployment of the app from a local machine.
  1. #Defined the Web Application Name and location  
  2. $webappname="DemoWebAppSbeeh1"  
  3. $location="West Europe"  
  4. $AppServicePlan="DemoWebApps"  

  5. #Create a resource group.  
  6. New-AzureRmResourceGroup -Name DemoResourceGroup -Location $location  

  7. #Create an App Service plan in Free tier.  
  8.  New-AzureRmAppServicePlan -Name $AppServicePlan -Location $location -ResourceGroupName DemoResourceGroup -Tier Free  

  9. #Create a web app.   
  10. New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $AppServicePlan -ResourceGroupName DemoResourceGroup  

  11. #Publish Web App  
  12. Publish-AzWebApp -ResourceGroupName DemoResourceGroup -Name $webappname -ArchivePath WebApplicationDemo.deps.zip  
Using Azure PowerShell Commands To Create An App Service Web App
 
Now, we need to test the web app by clicking the Web URL.
 
Using Azure PowerShell Commands To Create An App Service Web App
 
Using Azure PowerShell Commands To Create An App Service Web App
 

Clean Up Deployment

 
After the script sample has been run, the following command can be used to remove the resource group, web app, and all related resources.
  1. Remove-AzureRmResourceGroup -Name DemoResourceGroup -Force  

Thank you for reading!