VanixIsHere
VanixIsHere

Reputation: 11

How do I change a Platform Setting in an Azure Function App using a Powershell runbook

Specifically, I am looking to write an automation runbook for changing a Function App's HTTP Version from it's 1.1 default to 2.0. I know there is a simple way to do this via CLI commands, but I'm trying to get a working solution using a powershell runbook.

So far, I've been able to find the setting by doing...

$FA = Get-AzFunctionApp -Name <foo> -ResourceGroupName <bar>
$FA.Config.Http20Enabled
False

I've attempted to alter $FA and then pipe it through Update-AzFunctionApp...

$FA.Config.Http20Enabled = $True
$FA | Update-AzFunctionApp

with no success.

Not sure if I'm close to the right solution but I can't seem to find any Azure functionality that changes platform settings in this way. Any insight would be much appreciated!

Upvotes: 0

Views: 1031

Answers (2)

Liam L
Liam L

Reputation: 41

I found (as well as the Azure CLI) you can use the PowerShell cmdlets for Web Apps. These work on Azure Functions too!

For simple examples, perhaps to just toggle a feature you can call Set-AzWebApp in one line. Here are two examples:

(1) to enable HTTPS only:

Set-AzWebApp -Name $functionName -ResourceGroupName $rg -HttpsOnly $true

Or (2) to disable FTP/FTPs:

Set-AzWebApp -Name $functionName -ResourceGroupName $rg -FtpsState "Disabled"

For more complex property changes, like enabling HTTP 2.0. You can do this in just a few more lines of PowerShell. See for example:

$funcAsApp = Get-AzWebApp -Name $functionName -ResourceGroupName $rg
$funcAsApp.SiteConfig.Http20Enabled = $true
$funcAsApp | Set-AzWebApp

For more information see the MSDN help here: https://learn.microsoft.com/en-us/powershell/module/az.websites/set-azwebapp?view=azps-6.6.0

Upvotes: 0

VanixIsHere
VanixIsHere

Reputation: 11

I was able to find a solution to my original question. Instead of using the AzFunctionApp cmdlets, I used AzResource.

$FA = Get-AzResource -ResourceGroupName <foo> -Name <bar> -ResourceType Microsoft.Web/sites/config -ApiVersion 2021-02-01
$FA.Properties.http20Enabled = $True
Set-AzResource -ResourceId $FA.ResourceId -Properties $FA.Properties

I presume other config settings can be changed along with the property I needed.

Upvotes: 1

Related Questions