Skip to content

Instantly share code, notes, and snippets.

@mrichman
Created April 26, 2017 14:52
Show Gist options
  • Save mrichman/f68787b74b61c356c817cab5deeaa454 to your computer and use it in GitHub Desktop.
Save mrichman/f68787b74b61c356c817cab5deeaa454 to your computer and use it in GitHub Desktop.
Set Azure app service specific application settings (not web.config)
<#
.SYNOPSIS
Set Azure app service specific application settings (not web.config)
.DESCRIPTION
Set Azure app service specific application settings (not web.config)
.EXAMPLE
AzureSetAppSettings -ResourceGroupName "cmc-scm-tst-us-e-rg" -WebAppName "888888sisclientweb01"
.EXAMPLE
AzureSetAppSettings -ResourceGroupName "cmc-scm-tst-us-e-rg" -WebAppName "888888sisclientweb01" -Slot "qa"
.PARAMETER ResourceGroupName
Resource group name
.PARAMETER WebAppName
Web app name
.PARAMETER Slot
Optional slot name
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string]
$ResourceGroupName,
[Parameter(Mandatory=$True)]
[string]
$WebAppName,
[Parameter(Mandatory=$False)]
[string]
$Slot
)
$hash = @{}
if([string]::IsNullOrEmpty($Slot)) {
Write-Host "Using standard (non-slot) deployment"
$website = Get-AzureRmWebApp -Name $WebAppName -ResourceGroupName $ResourceGroupName
$currentAppSettings = $website.SiteConfig.AppSettings
ForEach ($kvp in $currentAppSettings) {
$hash[$kvp.Name] = $kvp.Value
}
$hash['WEBSITE_LOAD_CERTIFICATES'] = "*"
$hash['CertificateStoreLocation'] = "CurrentUser"
Set-AzureRmWebApp -Name $WebAppName -ResourceGroupName $ResourceGroupName -AppSettings $hash
}
else {
Write-Host "Using slot deployment"
$website = Get-AzureRmWebAppSlot -Name $WebAppName -ResourceGroupName $ResourceGroupName -Slot $Slot
$currentAppSettings = $website.SiteConfig.AppSettings
ForEach ($kvp in $currentAppSettings) {
$hash[$kvp.Name] = $kvp.Value
}
$hash['WEBSITE_LOAD_CERTIFICATES'] = "*"
$hash['CertificateStoreLocation'] = "CurrentUser"
Set-AzureRmWebAppSlot -Name $WebAppName -ResourceGroupName $ResourceGroupName -AppSettings $hash -Slot $Slot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment