gpt4 book ai didi

powershell - 使用 PowerShell 获取要交换的 Azure Web 应用设置列表

转载 作者:行者123 更新时间:2023-12-03 04:17:42 24 4
gpt4 key购买 nike

当我们通过 azure 门户执行交换时,它会向我们提供有关要交换的设置的警告和信息性消息。就像下图所示:enter image description here

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

我尝试用谷歌搜索但找不到任何方法。

最佳答案

直接的解决方案是使用Invoke-RestMethod来请求Portal中捕获的API。问题是,这是一个非公开 API,我们不知道它是否已发生变化。

您可以使用 PowerShell 获取要交换的两个对象,获取它们的 appSettingsConnectionStrings,然后比较它们。以下是一个脚本供引用。

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

$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 - 使用 PowerShell 获取要交换的 Azure Web 应用设置列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51671347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com