Skip to content

Instantly share code, notes, and snippets.

@ryanshripat
Last active September 27, 2018 13:13
Show Gist options
  • Save ryanshripat/2a04be9a34aceb2137496cc907780c18 to your computer and use it in GitHub Desktop.
Save ryanshripat/2a04be9a34aceb2137496cc907780c18 to your computer and use it in GitHub Desktop.
Powershell script to compare the Azure Portal Application Settings in one site to those of another
Clear-Host
Login-AzureRmAccount #Only necessary once per session
$SOURCE_SUBSCRIPTION_NAME = "YOUR SOURCE SUBSCRIPTION NAME"
$SOURCE_SITE = "YOUR SOURCE SITE NAME (xxxx in xxxx.azurewebsites.net)"
$TARGET_SUBSCRIPTION_NAME = "YOUR TARGET SUBSCRIPTION NAME"
$TARGET_SITE = "YOUR TARGET SITE NAME (xxxx in xxxx.azurewebsites.net)"
function GetSortedApplicationSettings ([string] $subscriptionName, [string] $siteName)
{
(Get-AzureRmSubscription -SubscriptionName $subscriptionName | Select-AzureRmSubscription) > $null
$sortedPortalAppSettings = New-Object System.Collections.SortedList
$webApp = Get-AzureRmWebApp -Name $siteName
$appSettingList = $webApp.SiteConfig.AppSettings
foreach($setting in $appSettingList)
{
$sortedPortalAppSettings.Add($setting.Name, $setting.Value)
}
return $sortedPortalAppSettings
}
#Get Source Portal App Settings
$sortedSourcePortalAppSettings = GetSortedApplicationSettings -subscriptionName $SOURCE_SUBSCRIPTION_NAME -siteName $SOURCE_SITE
Write-Host "SOURCE PORTAL APPSETTINGS ($SOURCE_SITE)" -ForegroundColor Yellow
$sortedSourcePortalAppSettings | Format-Table -AutoSize
#Get Target Portal App Settings
$sortedTargetPortalAppSettings = GetSortedApplicationSettings -subscriptionName $TARGET_SUBSCRIPTION_NAME -siteName $TARGET_SITE
Write-Host "TARGET PORTAL APPSETTINGS ($TARGET_SITE)" -ForegroundColor Yellow
$sortedTargetPortalAppSettings | Format-Table -AutoSize
Write-Host "COMPARISON PROGRESS" -ForegroundColor Yellow
$missingOnTarget = New-Object System.Collections.SortedList
foreach($sourceKey in $sortedSourcePortalAppSettings.Keys)
{
Write-Host "Checking entry $sourceKey ..."
if (!$sortedTargetPortalAppSettings.ContainsKey($sourceKey))
{
$sourceValue = $sortedSourcePortalAppSettings[$sourceKey]
$missingOnTarget.Add($sourceKey, $sourceValue)
Write-Host "Target ($TARGET_SITE) does not contain $sourceKey, which is present in Source ($SOURCE_SITE) with value: $sourceValue" -ForegroundColor Cyan
}
else
{
Write-Host "$sourceKey present in both sites." -ForegroundColor Green
}
}
if ($missingOnTarget.Count -gt 0)
{
Write-Host "`nDISCREPANCY REPORT" -ForegroundColor Yellow
Write-Host "The following keys are present in the source site ($SOURCE_SITE), but not in the target site ($TARGET_SITE)"
$missingOnTarget | Format-Table -AutoSize
}
else
{
Write-Host "`nNO DISCREPANCIES" -ForegroundColor Green
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment