Unable to Update a specific Application config in Function app through Powershell

Dhruv 1 Reputation point
2020-07-16T07:12:25.1+00:00

I am using a powershell script to update my function apps application settings. our developers recently introduced a new application config "tenant id". I have an xml file that contains all application configs for the app so i updated the new config setting there and ran my powershell script to update the function app. For the first run it was successful like other config values. But when i ran the script second time, my script was throwing error "tenant id" already exists when it was supposed to update it like other config values. I am not sure why its showing error for tenant id only and not other app configs which were also existing.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,512 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 69,931 Reputation points
    2020-07-21T12:24:34.53+00:00

    Hi @Dhruv-5639

    As you have shared the below command which makes me believe that the 'TenantId' key is the part of $settings object. Please correct me if my understanding is wrong.
    Set-AzureRMWebAppSlot -Name $name -ResourceGroupName $group -AppSettings $settings -Slot $slot

    If you are getting "TenantId already exists" for the object $settings then that means you are trying to add the same key to the object $settings and it is already present. So you only need to update the value for the key rather than adding the object again. Below is the sample script to update the value

    $webApp = Get-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -Slot $slotName $appSettingList = $webApp.SiteConfig.AppSettings

    $newvalue = @{}
    ForEach ($oldvalue in $appSettingList) {
    $newvalue[$oldvalue.Name] = $oldvalue.Value
    }
    $newvalue['TenantId'] = "yournewvalue"

    Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $newvalue -Slot $slotName

    If the error is coming from different object/command please share the full error message or screenshot

    0 comments No comments