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,
- Create a basic MVC Web App
- Create the resource group
- Create the App Service Plan
- Create a web app
- 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.
Select Web Application Template and click OK.
Next, build the project.
Then, right click on the project and select "Publish".
Select the destination and choose a target folder that will contain all publisher files.
Once deployed locally, navigate to the location where you stored the local deployment, select all, and zip them up.
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.
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.
From upload/download files, we need to upload the WebApplicationDemo.deps.zip that be created in the previous steps.
Then, type the below script. This is the script for creating a web app, and for deployment of the app from a local machine.
- #Defined the Web Application Name and location
- $webappname="DemoWebAppSbeeh1"
- $location="West Europe"
- $AppServicePlan="DemoWebApps"
- #Create a resource group.
- New-AzureRmResourceGroup -Name DemoResourceGroup -Location $location
- #Create an App Service plan in Free tier.
- New-AzureRmAppServicePlan -Name $AppServicePlan -Location $location -ResourceGroupName DemoResourceGroup -Tier Free
- #Create a web app.
- New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $AppServicePlan -ResourceGroupName DemoResourceGroup
- #Publish Web App
- Publish-AzWebApp -ResourceGroupName DemoResourceGroup -Name $webappname -ArchivePath WebApplicationDemo.deps.zip
Now, we need to test the web app by clicking the Web URL.
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.
- Remove-AzureRmResourceGroup -Name DemoResourceGroup -Force
Thank you for reading!