Is it possible to enable Always On for Azure websites through management/resource management APIs?

后端 未结 3 642
感情败类
感情败类 2021-01-04 09:23

I am writing some code for automatic deployment of Azure websites (including the creation of the website in Azure). I\'m using the Azure Management Libraries and Azure Resou

3条回答
  •  执笔经年
    2021-01-04 09:26

    Using updated ARM (Azure Resource Manager) Powershell, v1.0+

    Get-AzureRmResource: https://msdn.microsoft.com/en-us/library/mt652503.aspx

    Set-AzureRmResource: https://msdn.microsoft.com/en-us/library/mt652514.aspx

    # Variables - substitute your own values here
    $ResourceGroupName = 'My Azure RM Resource Group Name'
    $WebAppName = 'My Azure RM WebApp Name'
    $ClientAffinityEnabled = $false
    
    # Property object for nested, not exposed directly properties
    $WebAppPropertiesObject = @{"siteConfig" = @{"AlwaysOn" = $true}}
    
    # Variables
    $WebAppResourceType = 'microsoft.web/sites'
    
    # Get the resource from Azure (consider adding sanity checks, e.g. is $webAppResource -eq $null)
    $webAppResource = Get-AzureRmResource -ResourceType $WebAppResourceType -ResourceGroupName $ResourceGroupName -ResourceName $WebAppName
    
    # Set a directly exposed property, in this case whether client affinity is enabled
    $webAppResource.Properties.ClientAffinityEnabled = $ClientAffinityEnabled
    
    # Pass the resource object into the cmdlet that saves the changes to Azure
    $webAppResource | Set-AzureRmResource -PropertyObject $WebAppPropertiesObject -Force
    

提交回复
热议问题