获取要使用PowerShell交换的Azure

获取要使用PowerShell交换的Azure

本文介绍了获取要使用PowerShell交换的Azure Web应用程序设置的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们通过天蓝色门户执行交换时,它会向我们发出警告&有关要交换的设置的信息性消息.就像下面的图片一样:

When we perform the swap through the azure portal, it gives us the warning & informative messages regarding the settings to be swapped. Just like in below image:

我的问题是,有什么办法可以通过PowerShell代码获取这些消息列表(关于设置)?

My question is, is there any way I can get these messages list (regarding the settings) through PowerShell code?

我尝试使用Google搜索,但找不到任何方法.

I tried googling it but couldn't find any way.

推荐答案

直接的解决方案是使用 Invoke-RestMethod 请求在门户中捕获的API.问题在于这是一个非公开AP I,我们不知道它是否已更改.

The direct solution is to use the Invoke-RestMethod to request the API captured in the Portal. The problem is that this is a non-public API, and we don't know if it has changed.

您可以使用PowerShell来交换两个对象,获取它们的 appSettings ConnectionStrings 并进行比较.以下是参考脚本.

You could use PowerShell to get the two objects to be exchanged, gets their appSettings and ConnectionStrings, and compares them.The following is a script for reference.

当Source和Destination不同时,脚本可以得到:
•要添加到目的地"中
•要从目标"中删除的目标
•交换

When Source and Destination are different, the script can get:
• To be added in the Destination
• The destination to be removed from the Destination
• Exchanged

$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

希望它对您有帮助.

这篇关于获取要使用PowerShell交换的Azure Web应用程序设置的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:23