0
votes

I want to set an existing Azure function's app settings from Powershell. I have the following script

$FunctionSettings = @{     
    "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" = "*******";    
    "WEBSITE_CONTENTSHARE" = "TestFunction123";
    "AzureWebJobsStorage" = "*******";    
    "FUNCTIONS_EXTENSION_VERSION" = "~2";
    "FUNCTIONS_WORKER_RUNTIME" = "dotnet";       
    "WEBSITE_NODE_DEFAULT_VERSION" = "10.14.1";    
}

Set-AzureRmWebApp -ResourceGroupName "RGN" -AppSettings $FunctionSettings -Name "TestFunction"

Running this script returns this error

Set-AzureRmWebApp : Operation returned an invalid status code 'BadRequest' At C:\Users******\Source\Repos*******\Create Azure infrastructure.ps1:101 char:1 + Set-AzureRmWebApp -ResourceGroupName $AzureResourceGroupName -AppSett ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmWebApp], DefaultErrorResponseException + FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.SetAzureWebAppCmdlet

If I remove the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING and WEBSITE_CONTENTSHARE from $FunctionSettings then the script runs successfully but I get errors in the Azure UI because those properties are required.

How can I fix this?

1
Does your storage account support Blob, Queue, Table, and File storage? stackoverflow.com/questions/47637581/…Marie Hoeger
@MarieHoeger Thanks, I've checked that and it does support those. In fact if I create a new function through the web interface and select the same storage account, it works.Paul Hunt
Your comment means you create a new function and the script works fine? If not, could you try to use the Az command Set-AzWebApp? I tried it with a consumption function app, it works fine.Joy Wang-MSFT

1 Answers

0
votes

I know 1 year has passed and you probably solved your problem but today while I was creating a PS script I encountered the same problem. On my case the order of the settings did the trick. Put the WEBSITE_CONTENTSHARE first on your hastable.

    $AzFunctionAppSettings = @{}
    $AzFunctionAppSettings = @{
        APPINSIGHTS_INSTRUMENTATIONKEY = $AppInsightsKey
        APPLICATIONINSIGHTS_CONNECTION_STRING = $AppInsightsConString
        FUNCTIONS_EXTENSION_VERSION = "~1"
        FUNCTIONS_WORKER_RUNTIME = "dotnet"
        WEBSITE_CONTENTSHARE = "****"
        WEBSITE_CONTENTAZUREFILECONNECTIONSTRING = "***"
    }