Skip to content

Instantly share code, notes, and snippets.

@deeja
Created October 16, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeja/72b773b7bb4ce892e9d02cb5ca237fc6 to your computer and use it in GitHub Desktop.
Save deeja/72b773b7bb4ce892e9d02cb5ca237fc6 to your computer and use it in GitHub Desktop.
Azure Powershell Set ConnectionStrings and App Settings
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