Is it possible to easily copy applications settings from one web app to another on azure

前端 未结 3 783
既然无缘
既然无缘 2021-02-05 22:13

I was wondering if there is an easy way to completely copy all the key values from one web app\'s application settings to another, as seen in the below picture I have a lot of t

3条回答
  •  名媛妹妹
    2021-02-05 22:27

    You can use Azure PowerShell. Here is a PowerShell Script for you.

    try{
        $acct = Get-AzureRmSubscription
    }
    catch{
        Login-AzureRmAccount
    }
    
    $myResourceGroup = ''
    $mySite = ''
    $myResourceGroup2 = ''
    $mySite2 = ''
    
    $props = (Invoke-AzureRmResourceAction -ResourceGroupName $myResourceGroup `
            -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
            -Action list -ApiVersion 2015-08-01 -Force).Properties
    
    $hash = @{}
    $props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }
    
    Set-AzureRMWebApp -ResourceGroupName $myResourceGroup2 `
            -Name $mySite2 -AppSettings $hash
    

    This script copy app settings from $mySite to $mySite2. If your web app involves with slot, for $props, you should use the following command instead.

    $props = (Invoke-AzureRmResourceAction -ResourceGroupName $myResourceGroup `
            -ResourceType Microsoft.Web/sites/slots/Config -Name $mySite/$slot/appsettings `
            -Action list -ApiVersion 2015-08-01 -Force).Properties 
    

    And, use Set-AzureRMWebAppSlot instead of Set-AzureRMWebApp

    Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup2 `
            -Name $mySite2 -Slot $slot -AppSettings $hash
    

提交回复
热议问题