Skip to content

Instantly share code, notes, and snippets.

@sajeetharan
Created April 18, 2020 16:22
Show Gist options
  • Save sajeetharan/d80f55ef3c2b7d66420a3e1e348b9919 to your computer and use it in GitHub Desktop.
Save sajeetharan/d80f55ef3c2b7d66420a3e1e348b9919 to your computer and use it in GitHub Desktop.
$rsgName = "xxxxx"
$appName = "xxxxx"
$slotName = "xxxxxx"
$destination = Get-AzureRmWebApp -ResourceGroupName $rsgName -Name $appName
$destinationAppSettings = $destination.SiteConfig.AppSettings
$destinationConnectionStrings = $destination.SiteConfig.ConnectionStrings
$source = Get-AzureRmWebAppSlot -ResourceGroupName $rsgName -Name $appName -Slot $slotName
$sourceAppSettings = $source.SiteConfig.AppSettings
$sourceConnectionStrings = $source.SiteConfig.ConnectionStrings
#Get slot configurations
$slotConfigure = Get-AzureRmWebAppSlotConfigName -ResourceGroupName $rsgName -Name $appName
$toBeAdded = New-Object System.Collections.ArrayList
$toBeSwapped = New-Object System.Collections.ArrayList
$toBeDeleted = New-Object System.Collections.ArrayList
foreach($appSetting in $sourceAppSettings){
if(-not $slotConfigure.AppSettingNames.Contains($sourceAppSettings.Name)){
$flag = $true
foreach($_appSetting in $destinationAppSettings){
if($_appSetting.Name -eq $appSetting.Name){
$flag = $false
[void]$toBeSwapped.Add([pscustomobject]@{Name = $appSetting.Name; Source = $appSetting.Value; Destination = $_appSetting.Value})
}
}
if($flag){
[void]$toBeAdded.Add($appSetting)
}
}
}
foreach($appSetting in $destinationAppSettings){
$flag = $true
foreach($_appSetting in $sourceAppSettings){
if($_appSetting.Name -eq $appSetting.Name){
$flag = $false
}
}
if($flag){
[void]$toBeDeleted.Add($appSetting)
}
}
# AppSettings
# To be added to destination
$toBeAdded
# To be swapped to destination
$toBeSwapped
# To be delete in destination
$toBeDeleted
$toBeAdded = New-Object System.Collections.ArrayList
$toBeSwapped = New-Object System.Collections.ArrayList
$toBeDeleted = New-Object System.Collections.ArrayList
foreach($connectionString in $sourceConnectionStrings){
if(-not $slotConfigure.ConnectionStringNames.Contains($connectionString.Name)){
$flag = $true
foreach($_connectionString in $destinationConnectionStrings){
if($_connectionString.Name -eq $connectionString.Name){
$flag = $false
[void]$toBeSwapped.Add([pscustomobject]@{Name = $connectionString.Name; Source = $connectionString.Value; Destination = $_connectionString.Value})
}
}
if($flag){
[void]$toBeAdded.Add($connectionString)
}
}
}
foreach($connectionString in $destinationConnectionStrings){
$flag = $true
foreach($_connectionString in $sourceConnectionStrings){
if($_connectionString.Name -eq $connectionString.Name){
$flag = $false
}
}
if($flag){
[void]$toBeDeleted.Add($connectionString)
}
}
# ConnectionStrings
# To be added to destination
$toBeAdded
# To be swapped to destination
$toBeSwapped
# To be delete in destination
$toBeDeleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment