Created
October 16, 2019 15:18
-
-
Save deeja/72b773b7bb4ce892e9d02cb5ca237fc6 to your computer and use it in GitHub Desktop.
Azure Powershell Set ConnectionStrings and App Settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function UpdateConnectionStrings { | |
param( | |
[string]$ResourceGroup, | |
[string]$WebAppName, | |
[string]$Slot, | |
[hashtable]$ConnectionStrings, | |
[hashtable]$AppSettings | |
) | |
Write-Host "Loading Existing Connectionstrings" | |
$webApp = Get-AzureRmWebAppSlot -ResourceGroupName $ResourceGroup -Name $WebAppName -Slot $Slot | |
Write-Host "Applying New AppSettings" | |
$appSettinghash = @{} | |
ForEach ($kvp in $webApp.SiteConfig.AppSettings) { | |
$appSettinghash[$kvp.Name] = $kvp.Value | |
} | |
ForEach ($key in $AppSettings.Keys) { | |
$appSettinghash[$key] = $AppSettings[$key] | |
} | |
Write-Host "Applying New Connectionstrings" | |
$connstringhash = @{} | |
# adds existings connections strings to the hash so they are lost | |
ForEach ($kvp in $webApp.SiteConfig.ConnectionStrings) { | |
$connstringhash[$kvp.Name] = @{ Type=$kvp.Type; Value = $kvp.ConnectionString } | |
Write-Host $connstringhash[$kvp.Name] | |
} | |
# adds new connection strings to has | |
ForEach ($key in $ConnectionStrings.Keys) { | |
$connstringhash[$key] = $ConnectionStrings[$key] | |
Write-Host $connstringhash[$kvp.Name] | |
} | |
Write-Host "Saving ConnectionStrings and App Settings" | |
Set-AzureRMWebAppSlot -ResourceGroupName $ResourceGroup -Name $WebAppName -ConnectionStrings $connstringhash -AppSettings $appSettinghash -Slot $Slot | Out-Null | |
Write-Host "ConnectionStrings Updated" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment