Drücke "Enter", um den Text zu überspringen.

Azure – Application Settings von einem App Service zu einem anderen Kopieren

Wenn man beispielsweise für Entwicklung, Test und andere Zwecke Kopien einer Azure Web App benötigt oder zumindest initial die Settings übernehmen will, kann das, bei einer längeren Liste von Settings, ein recht hoher manueller Aufwand werden. Um diesen zu umgehen, habe ich ein entsprechendes PowerShell-Skript geschrieben. Dieses kopiert alle Settings und deren Werte von einer benannten Web App auf eine andere. Dabei sind die Ressource Groups und die Namen der Web Apps anzugeben.

Hier das Skript im Textlaut:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Adjust theese as needed
 
$SubscriptionId = "FILLINSUBSCRIPTIONID"
 
$ResourceGroupSource = "FILLINRGOFSOURCEWEBAPP"
$ResourceGroupTarget = "FILLINRGOFDESTWEBAPP"
 
$WebAppSource = "FILLINSOURCEWEBAPP"
$WebAppTarget = "FILLINDESTWEBAPP"
 
### no changes needed below ###
 
Connect-AzureRmAccount -Subscription $SubscriptionId
Set-AzureRmContext -SubscriptionId $SubscriptionId
 
$webAppSource = Get-AzureRmWebApp -ResourceGroupName $ResourceGroupSource -Name $WebAppSource 
 
# Get reference to the source app settings
$AppSettingsSource = $WebAppSource.SiteConfig.AppSettings
 
# Create empty Hash table variable for App Settings
$AppSettingsTarget = @{}
 
# Copy over all Existing App Settings to the Hash table
ForEach ($AppSettingSource in $AppSettingsSource) {
    $AppSettingsTarget[$AppSettingSource.Name] = $AppSettingSource.Value
}
 
# Save Connection Strings to Target Web App
Set-AzureRmWebApp -ResourceGroupName $ResourceGroupTarget -Name $WebAppTarget -AppSettings $AppSettingsTarget
Write-Host "Done!"

Viel Spaß damit!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

CAPTCHA image
*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.