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

拥有回忆 提交于 2020-01-03 08:53:12

问题


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"?


回答1:


"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

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.



来源:https://stackoverflow.com/questions/40794622/azure-powershell-set-azurermwebapp-how-to-set-the-alwayson-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!