Azure powershell – update an app setting without erasing them

Another simple script that updates an app setting. This one grabs the existing app settings of an Azure web app into a hash table that you can then add more hashes to. It’s nice because I manage a lot of web apps with different settings and I don’t want to carry over unnecessary settings from one app to another by just using the same settings for each app. Also, if you just update app settings by themselves the cmdlet is designed to replace all the app settings with what you put in the hash table. This method allows you to grab those app settings, put them in the hash table, and then add whatever new one or replace an existing (with the same key name).

$apps = Get-AzureRmWebApp
$appnames = ($apps).Name
$rg = "name of resource group"
ForEach ($appname in $appnames) {
$webApp = Get-AzureRmwebApp -ResourceGroupName $rg -Name $appname
$webAppSettings = $webApp.SiteConfig.AppSettings
$hash = @{}
foreach ($setting in $webAppSettings) {
$hash[$setting.Name] = $setting.Value
$hash['New name'] = "new Value"
}
Set-AzureRMWebAppSlot -ResourceGroupName $rg -Name $appname -AppSettings $hash -Slot production
Set-AzureRMWebAppSlot -ResourceGroupName $rg -Name $appname -AppSettings $hash -Slot staging
}

 

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.