Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure: Powershell: Set-AzureRmWebApp: How to set the "alwaysOn" property

I am running Powershell 5 and trying to manipulate my Azure WebApp object using Set-AzureRmWebApp (and NOT Set-AzureResource) to set the "Always On" property of the web app.

My basic code snippet starts with a running web app named "myWebApp", and looks like this:

$name = "myWebApp"
$resourceGroupName = "myResourceGroup"
$app_settings = @{"WEBSITE_LOAD_CERTIFICATES"="*";"CommonDatabase"="Common";"WEBSITE_NODE_DEFAULT_VERSION"="0.10.32"}

$result1 = Set-AzureRmWebApp -ResourceGroupName $resourceGroupName -AppSettings $app_settings -Name $name
$result2 = Set-AzureRmResource -ResourceGroupName $resourceGroupName  -ResourceType Microsoft.Web/sites/config -ResourceName $this.name -PropertyObject $propertiesObject -ApiVersion 2015-08-01 -Force

The first Set-AzureRmWebApp statement works. It sets all the variables in $app_settings, and they become visible in the Azure Portal blade for myWebApp.

I tried using "Always On"= on as a property in $app_settings with Set-AzureRmWebApp, and it appeared in the App Settings sub-list in the properties of "myWebApp" on the Azure portal blade, but the actual property "Always On" in the general settings remained off.

I read on another site that using Set-AzureRmResource would work, so I tried it, but it failed.

What do I need to do in Powershell to set a property in the General Settings of my Azure WebApp, specifically "Always On"?

like image 524
Jay Godse Avatar asked Nov 24 '16 21:11

Jay Godse


1 Answers

"Always On" is not supported if WebApp is in a free Service Plan tier. If the WebApp is in a free tier, please scale up the App Service Plan. Please refer to the document for more info about how to scale up the App Service Plan.Please have a try to use the solution that sharbag mentioned. It is worked for me and I also check the run result from the azure portal. Snipped code from the solution is as followings:

   $ResourceGroupName = 'Your Group Name'

   $WebAppName = 'Your WebApp Name'

   $WebAppPropertiesObject = @{"siteConfig" = @{"AlwaysOn" = $true}}

    $WebAppResourceType = 'microsoft.web/sites'

    $webAppResource = Get-AzureRmResource -ResourceType $WebAppResourceType -ResourceGroupName $ResourceGroupName -ResourceName $WebAppName

    $webAppResource | Set-AzureRmResource -PropertyObject $WebAppPropertiesObject -Force

enter image description here

If the WebApp in a free tier service plan, when we try to run the PowerShell command to enable "Always On" then we will get the following error message.

enter image description here

like image 151
Tom Sun - MSFT Avatar answered Oct 04 '22 18:10

Tom Sun - MSFT