You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Web App Slot的全部配置项(非仅部署槽设置)

获取Web App Slot所有当前配置的方法

你可以使用Get-AzWebAppSlot命令获取指定Web App槽的所有当前生效配置,包括所有App Settings和Connection Strings,无论这些配置是否被标记为Deployment Slot设置。该命令能返回槽的完整运行时配置,自然包含槽交换后引入的非槽设置项。

基础用法示例

# 替换为你的资源组、Web App名称和槽名称
$resourceGroup = "myresourcegroup"
$webAppName = "mywebapp"
$slotName = "yourslotname"

# 获取目标槽的完整配置
$webAppSlot = Get-AzWebAppSlot -ResourceGroupName $resourceGroup -Name $webAppName -Slot $slotName

# 输出所有App Settings
Write-Host "=== 所有App Settings ==="
$webAppSlot.SiteConfig.AppSettings | Format-Table Name, Value -AutoSize

# 输出所有Connection Strings
Write-Host "`n=== 所有Connection Strings ==="
$webAppSlot.SiteConfig.ConnectionStrings | Format-Table Name, ConnectionString, Type -AutoSize

区分Deployment Slot设置与非设置项(可选)

如果需要区分哪些配置是标记为Deployment Slot的(交换时不被替换),可以结合Get-AzWebAppSlotConfigName的结果对比:

# 获取标记为Deployment Slot的配置项名称
$slotConfig = Get-AzWebAppSlotConfigName -ResourceGroupName $resourceGroup -Name $webAppName

# 筛选标记为Deployment Slot的App Settings
Write-Host "=== 标记为Deployment Slot的App Settings ==="
$webAppSlot.SiteConfig.AppSettings | Where-Object { $slotConfig.AppSettingNames -contains $_.Name } | Format-Table Name, Value -AutoSize

# 筛选非Deployment Slot的App Settings
Write-Host "`n=== 非Deployment Slot的App Settings ==="
$webAppSlot.SiteConfig.AppSettings | Where-Object { $slotConfig.AppSettingNames -notcontains $_.Name } | Format-Table Name, Value -AutoSize

# 同理处理Connection Strings
Write-Host "`n=== 标记为Deployment Slot的Connection Strings ==="
$webAppSlot.SiteConfig.ConnectionStrings | Where-Object { $slotConfig.ConnectionStringNames -contains $_.Name } | Format-Table Name, ConnectionString, Type -AutoSize

Write-Host "`n=== 非Deployment Slot的Connection Strings ==="
$webAppSlot.SiteConfig.ConnectionStrings | Where-Object { $slotConfig.ConnectionStringNames -notcontains $_.Name } | Format-Table Name, ConnectionString, Type -AutoSize

说明

  • Get-AzWebAppSlotConfigName仅返回被标记为"Deployment Slot设置"的配置项名称,这类配置在槽交换过程中不会被覆盖。
  • Get-AzWebAppSlot返回的是槽当前实际运行的完整配置,包含所有生效的App Settings和Connection Strings,包括槽交换后引入的非槽设置项,完全满足你的需求。

内容的提问来源于stack exchange,提问作者Kode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 08:37:30