How to create an Azure web app using PowerShell

How to create an Azure web app using PowerShell

In this Azure tutorial, we will discuss how to create an Azure web app from the Azure Portal. Also, we will discuss how to create an Azure web app using PowerShell, Azure web app pricing, Create App Service Plan Azure PowerShell, New-AzWebApp, Get-AzWebApp, Set-AzWebApp, Publish-AzWebApp.

Create an Azure web app from Azure Portal

Here, we will discuss how to setup azure web app from the Azure portal.

Azure Web App is an excellent service in Azure and it is one of the cheap service in market now.

One of the advantage of the Azure App is it supports different languages like java, .net, PHP etc.

There are various benefits of using Azure app Service

  • Supports multiple languages like Java, .Net, PHP, etc
  • It supports continuous deployment and integration
  • High availability and scalability support.
  • Supports other platform integration.

Follow the below steps to create an Azure web App in Azure portal.

Step- 1:

Login to Azure Portal (https://portal.azure.com/)

Step- 2:

Click on the + Create a resource button from the left navigation.

How to create an Azure web app

Or for the same option, you can click on the + Create a resource button from the Azure services section.

How to create a web app in Azure

Step-3:

In the New page, search for the Web app now click on the search result Web app.

How to configure a web app in Azure

Now you will see the below screen

How to configure a web app in Azure

Now for the same option, you can search for App services after login to the Azure portal.

How to configure a web app in Azure

Click on the search result App Services and click on the Add button.

How to add a web app in Azure

Step-5:

In the web app window, fill the below details

  • Subscription: Select your subscription details.
  • Resource Group: You can select the existing resource group or you can create a new one also by clicking on the Create new link.
  • Name: You need to provide a name for the web app.
  • Publish: You can select the Code option here.
  • Runtime stack: I choose here .Net core 3.1 (LTS). You can also choose a different one.
  • Operating System: You can choose either Linux or Windows based on your need.
  • Region: You can select your region.
  • Linux plan (Central US): Based on your region and other value selection, this field will auto-populate or you can also create a new one by clicking on the Create new link.
  • SKU and size: I change the size because there is a free offer (Free offer 1 GB Memory) from Microsoft for Linux operating system.
How do I make an Azure web app?
Azure web app

To change the Sku and size, click on the Change size link .

In the Spec Picker window, click on Dev/Test section, choose F1 (1 GB memory, 60 minutes/day compute free) but you can also choose on your choice based on your requirement, click on the Apply button.

Now go to the Monitoring tab by clicking on the Next : Monitoring > button.

create a web app in Azure portal

Step-6:

In the Monitoring tab, No need to change anything. Keep the Enable Application Insights option as No.

Now click on the Next : Tags > button to go to the Tags tab.

Microsoft Azure web app pricing

Step-7:

In the Tags window, keep the default option as it is and then click on the Next:Review + Create button.

How to create an Azure web app

Step-8:

Now click on the Create to create an Azure web app.

How to create a web application in Azure

Now you can see it is in progress to create the web app in Azure

How to create a web application in Azure

Deployment is completed now. Click on the Go to resource button to see the web app.

How to add a web application in Azure

See Here it is, It created successfully.

How to deploy a web application in Azure

How to create an Azure web app using PowerShell?

Now it is time to see how to create an Azure web app using PowerShell?

1- Need to specify the web app name and the Region using PowerShell. Use the below PowerShell window or PowerShell ISE.

#Specify the Web app Name and Region
$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
How to create an Azure web app using PowerShell

2- You can create a resource group or you can use the existing resource group. Use the below cmdlet to create the resource group using PowerShell

New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
Create an Azure web app using PowerShell

3- You can create an App Service plan using the free tier

New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName mynewupdtrsggroup -Tier Free
How to set an Azure web app using PowerShell

4- Now we need to create the web app using the below PowerShell cmdlet.

New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName mynewupdtrsggroup 
create an Azure web app using PowerShell

5- Now run the below complete script to create the web app in Azure

$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName mynewupdtrsggroup -Tier Free
New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName mynewupdtrsggroup 
How to set  an Azure web app using PowerShell

This is how we can create Azure web app using PowerShell.

Azure web app pricing

Below are few pricing details for Azure web App service

FREESHAREDEnvironment for dev/testBASICDedicated environment for dev/testSTANDARDRun production workloadsPREMIUMEnhanced performance and scaleISOLATEDHigh-Performance, Security and Isolation
Web, mobile or API apps10100No limitNo limitNo limitNo limit
Disk space1 GB1 GB10 GB50 GB250 GB1 TB
Custom domainSupportedSupportedSupportedSupportedSupported
PriceFree₹0.860/hour₹4.958/hour₹6.610/hour₹13.220/hour₹26.439/hour

For more details on Azure web app pricing you can follow the official website.

Create App Service Plan Azure PowerShell

Well, it’s quite easy to create an App Service plan in Azure using PowerShell. You can use the below Azure PowerShell cmdlet to create the App Service Plan in Azure.

New-AzAppServicePlan

New-AzAppServicePlan is one of excellent Azure PowerShell cmdlet that can help you to quickly create an App service plan for a specific region.

You need to specify a few parameters like name, location, tier, number of workers, worker size, etc.

Syntax:

The syntax of the New-AzAppServicePlan Azure PowerShell cmdlet is as below.

New-AzAppServicePlan
 [-Location] <String>
 [[-Tier] <String>]
[[-NumberofWorkers] <Int32>]
[[-WorkerSize] <String>]
[[-AseName] <String>]
[[-AseResourceGroupName] <String>]
[-PerSiteScaling <Boolean>]
[-AsJob]
[-AppServicePlan] <PSAppServicePlan>
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Example

Let’s consider the below example. Here we will create an App Service plan named “TSINFOASP12” with the resource group name “Demo123“, Location is “East US”, Tier is “Basic“, Number of workers is 2 and the worker size is “Small“.

Execute the below Azure PowerShell Cmdlet.

PS C:\WINDOWS\system32> New-AzAppServicePlan -ResourceGroupName "Demo123" -Name "TSINFOASP12" -Location "East US" -Tier "Basic" -NumberofWorkers 2 -WorkerSize "Small"

Once, you will execute the above PowerShell cmdlet, you will get the output like below

AdminSiteName             : 
WorkerTierName            : 
Status                    : Ready
Subscription              : 1cdf4300-dee5-4518-9c9c-feaa72a5cbd1
HostingEnvironmentProfile : 
MaximumNumberOfWorkers    : 0
GeoRegion                 : East US
PerSiteScaling            : False
MaximumElasticWorkerCount : 
NumberOfSites             : 0
IsSpot                    : False
SpotExpirationTime        : 
FreeOfferExpirationTime   : 
ResourceGroup             : Demo123
Reserved                  : False
IsXenon                   : False
HyperV                    : 
TargetWorkerCount         : 0
TargetWorkerSizeId        : 0
ProvisioningState         : Succeeded
Sku                       : Microsoft.Azure.Management.WebSites.Models.SkuDescription
Id                        : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resour
                            ceGroups/Demo123/providers/Microsoft.Web/serverfarms/TSINF
                            OASP12
Name                      : TSINFOASP12
Kind                      : app
Location                  : East US
Type                      : Microsoft.Web/serverfarms
Tags                      : 

You can see it here.

Create App Service Plan Azure PowerShell

Now, just to cross-check, you can log in to the Azure Portal, and search for the App Service plan that we have created. You can able to see the App Service Plan has been created successfully.

how to create App service plan in Azure using PowerShell

This is how to create App service plan in Azure using PowerShell.

New-AzWebApp

New-AzWebApp is an excellent Azure PowerShell cmdlet that can help you to quickly create an Azure Web App for a specified resource group, App Service Plan.

You need to specify a few key parameters along with this Azure PowerShell cmdlet like name, resource group name, location and App Service Plan, etc.

Syntax

The syntax of the New-AzWebApp Azure PowerShell cmdlet is as below.

New-AzWebApp
[[-ResourceGroupName] <String>]
 [-Name] <String>
 [[-Location] <String>]
   [[-AppServicePlan] <String>]
 [-ContainerImageName <String>]
[-EnableContainerContinuousDeployment]
 [-AsJob]
[-GitRepositoryPath <String>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

Example

Let’s consider the below example. Here we will create an Azure Web App named “TSINFOSite” with the resource group name “Demo123“, Location is “East US”, and the App Service Plan as “TSINFOASP12“.

Execute the below Azure PowerShell Cmdlet.

PS C:\WINDOWS\system32> New-AzWebApp -ResourceGroupName Demo123 -Name "TSINFOSite" -Location "East US" -AppServicePlan "TSINFOASP12
"

Once, you will execute the above Azure PowerShell cmdlet, you will get the output like below

GitRemoteName               : 
GitRemoteUri                : 
GitRemoteUsername           : 
GitRemotePassword           : 
AzureStorageAccounts        : 
AzureStoragePath            : 
State                       : Running
HostNames                   : {tsinfosite.azurewebsites.net}
RepositorySiteName          : TSINFOSite
UsageState                  : Normal
Enabled                     : True
EnabledHostNames            : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
AvailabilityState           : Normal
HostNameSslStates           : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
ServerFarmId                : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/serverfarms/T
                              SINFOASP12
Reserved                    : False
IsXenon                     : False
HyperV                      : 
LastModifiedTimeUtc         : 6/25/2021 3:07:32 AM
SiteConfig                  : Microsoft.Azure.Management.WebSites.Models.SiteConfig
TrafficManagerHostNames     : 
ScmSiteAlsoStopped          : False
TargetSwapSlot              : 
HostingEnvironmentProfile   : 
ClientAffinityEnabled       : True
ClientCertEnabled           : False
ClientCertMode              : 
ClientCertExclusionPaths    : 
HostNamesDisabled           : False
CustomDomainVerificationId  : 
OutboundIpAddresses         : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232
PossibleOutboundIpAddresses : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232,52.179.2.103,52.170.87.19
ContainerSize               : 0
DailyMemoryTimeQuota        : 0
SuspendedTill               : 
MaxNumberOfWorkers          : 
CloningInfo                 : 
ResourceGroup               : Demo123
IsDefaultContainer          : 
DefaultHostName             : tsinfosite.azurewebsites.net
SlotSwapStatus              : 
HttpsOnly                   : False
RedundancyMode              : 
InProgressOperationId       : 
Identity                    : 
Id                          : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/sites/TSINFOS
                              ite
Name                        : TSINFOSite
Kind                        : app
Location                    : East US
Type                        : Microsoft.Web/sites
Tags                        : 

You can see it here

New-AzWebApp

Get-AzWebApp

Get-AzWebApp is an excellent Azure PowerShell cmdlet that helps you to quickly retrieve the information about your Azure Web App.

The key parameters you need to provide with Get-AzWebApp are Azure Web App name, resource group name, etc.

Syntax

The syntax of the Get-AzWebApp Azure PowerShell cmdlet is as below

Get-AzWebApp [[-ResourceGroupName] <String>] [[-Name] <String>]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]

Example

You can consider the below example. Here we will retrieve the details for the Azure Web App named “TSINFOSite” with the resource group name “Demo123“.

Execute the below Azure PowerShell Cmdlet.

PS C:\WINDOWS\system32> Get-AzWebApp -ResourceGroupName "Demo123" -Name "TSINFOSite"

Once, you will execute the above Azure PowerShell cmdlet, you will get the below output

GitRemoteName               : 
GitRemoteUri                : 
GitRemoteUsername           : 
GitRemotePassword           : 
AzureStorageAccounts        : 
AzureStoragePath            : {}
State                       : Running
HostNames                   : {tsinfosite.azurewebsites.net}
RepositorySiteName          : TSINFOSite
UsageState                  : Normal
Enabled                     : True
EnabledHostNames            : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
AvailabilityState           : Normal
HostNameSslStates           : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
ServerFarmId                : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/serverfarms/T
                              SINFOASP12
Reserved                    : False
IsXenon                     : False
HyperV                      : 
LastModifiedTimeUtc         : 6/25/2021 3:07:32 AM
SiteConfig                  : Microsoft.Azure.Management.WebSites.Models.SiteConfig
TrafficManagerHostNames     : 
ScmSiteAlsoStopped          : False
TargetSwapSlot              : 
HostingEnvironmentProfile   : 
ClientAffinityEnabled       : True
ClientCertEnabled           : False
ClientCertMode              : 
ClientCertExclusionPaths    : 
HostNamesDisabled           : False
CustomDomainVerificationId  : 
OutboundIpAddresses         : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232
PossibleOutboundIpAddresses : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232,52.179.2.103,52.170.87.19
ContainerSize               : 0
DailyMemoryTimeQuota        : 0
SuspendedTill               : 
MaxNumberOfWorkers          : 
CloningInfo                 : 
ResourceGroup               : Demo123
IsDefaultContainer          : 
DefaultHostName             : tsinfosite.azurewebsites.net
SlotSwapStatus              : 
HttpsOnly                   : False
RedundancyMode              : 
InProgressOperationId       : 
Identity                    : 
Id                          : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/sites/TSINFOS
                              ite
Name                        : TSINFOSite
Kind                        : app
Location                    : East US
Type                        : Microsoft.Web/sites
Tags                        : 

You can see it here

Get-AzWebApp

Set-AzWebApp

Set-AzWebApp is an Azure PowerShell cmdlet that can help you to modify your Azure Web App.

Syntax:

The syntax of the Set-AzWebApp Azure PowerShell cmdlet is as below.

Set-AzWebApp
 [[-Use32BitWorkerProcess] <Boolean>]
 [[-AutoSwapSlotName] <String>]
   [-NumberOfWorkers <Int32>]
 [-AsJob]
[-WebApp] <PSSite>
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]

Or, you can find out another syntax of Set-AzWebApp

Example:

You can consider the below example. Here we will change the App Service Plan for the Azure Web App named “TSINFOSite” from “TSINFOASP12” to “TSINFOASPNEW” with the resource group name “Demo123“.

Execute the below Azure PowerShell cmdlet

PS C:\WINDOWS\system32> Set-AzWebApp -ResourceGroupName "Demo123" -Name "TSINFOSite" -AppServicePlan "TSINFOASPNEW"

Once, you will execute the above Azure PowerShell cmdlet, you will get the output like below.

GitRemoteName               : 
GitRemoteUri                : 
GitRemoteUsername           : 
GitRemotePassword           : 
AzureStorageAccounts        : 
AzureStoragePath            : {}
State                       : Running
HostNames                   : {tsinfosite.azurewebsites.net}
RepositorySiteName          : TSINFOSite
UsageState                  : Normal
Enabled                     : True
EnabledHostNames            : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
AvailabilityState           : Normal
HostNameSslStates           : {tsinfosite.azurewebsites.net, 
                              tsinfosite.scm.azurewebsites.net}
ServerFarmId                : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/serverfarms/T
                              SINFOASPNEW
Reserved                    : False
IsXenon                     : False
HyperV                      : 
LastModifiedTimeUtc         : 6/25/2021 4:12:49 AM
SiteConfig                  : Microsoft.Azure.Management.WebSites.Models.SiteConfig
TrafficManagerHostNames     : 
ScmSiteAlsoStopped          : False
TargetSwapSlot              : 
HostingEnvironmentProfile   : 
ClientAffinityEnabled       : True
ClientCertEnabled           : False
ClientCertMode              : 
ClientCertExclusionPaths    : 
HostNamesDisabled           : False
CustomDomainVerificationId  : 
OutboundIpAddresses         : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232
PossibleOutboundIpAddresses : 52.170.7.25,52.168.75.147,52.179.5.98,52.179.1.81,52.179
                              .4.232,52.179.2.103,52.170.87.19
ContainerSize               : 0
DailyMemoryTimeQuota        : 0
SuspendedTill               : 
MaxNumberOfWorkers          : 
CloningInfo                 : 
ResourceGroup               : Demo123
IsDefaultContainer          : 
DefaultHostName             : tsinfosite.azurewebsites.net
SlotSwapStatus              : 
HttpsOnly                   : False
RedundancyMode              : 
InProgressOperationId       : 
Identity                    : 
Id                          : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Web/sites/TSINFOS
                              ite
Name                        : TSINFOSite
Kind                        : app
Location                    : East US
Type                        : Microsoft.Web/sites
Tags                        : 

You can see that here

Set-AzWebApp

Publish-AzWebApp

Publish-AzWebApp is an Azure PowerShell cmdlet that helps you upload the content to an existing Azure Web App. The only thing is the content should be packaged in a ZIP file.

Basically, it helps you to deploy the Azure Web App from a ZIP or WAR file with the help of zipdeploy.

Syntax

The Syntax of the Publish-AzWebApp Azure PowerShell cmdlet is as below

Publish-AzWebApp
 -ArchivePath <String>
 [-AsJob]
 [-ResourceGroupName] <String>
       [-Name] <String>
 [[-Slot] <String>]
[-Force]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]

Example:

PS C:\WINDOWS\system32> Publish-AzWebApp -ResourceGroupName Demo123 -Name TSINFOWebApp -ArchivePath C:\MyWork\tsinfoapp.zip

Once, you will execute the above Azure PowerShell cmdlet, it deploys the content inside the tsinfoapp.zip file to the web app named as TSINFOWebApp that belongs to the resource group Demo123.

Create Azure web app – Video Tutorial

You may like following the below Azure tutorials:

Conclusion

In this Azure tutorial, we will discuss how to create an Azure web app from the Azure portal as well as how to create an Azure web app using PowerShell. Also, we discussed Azure web app pricing, Create App Service Plan Azure PowerShell, How to Create App Service Plan in Azure using PowerShell, New-AzWebApp, Get-AzWebApp, Set-AzWebApp, Publish-AzWebApp.

Hope you have enjoyed this article !!!