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

如何用PowerShell在Exchange 2019 web.config的appSettings节添加新键值对

在Exchange 2019中通过PowerShell给web.config的appSettings添加指定节点

操作前准备

  • 先备份目标web.config文件,防止操作失误引发问题,默认路径为C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\owa\web.config(若操作其他虚拟目录,对应调整路径即可)
  • 以本地管理员/Exchange管理员权限运行PowerShell

完整PowerShell代码

# 定义web.config文件路径,根据实际场景修改
$webConfigPath = "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess\owa\web.config"

# 加载XML配置文件
$xml = [xml](Get-Content $webConfigPath)

# 获取appSettings节点
$appSettings = $xml.configuration.appSettings

# 检查目标键是否已存在
$existingKey = $appSettings.add | Where-Object { $_.key -eq "KillBitRefreshTimeInSeconds" }

if (-not $existingKey) {
    # 创建新的add节点
    $newAddNode = $xml.CreateElement("add")
    $newAddNode.SetAttribute("key", "KillBitRefreshTimeInSeconds")
    $newAddNode.SetAttribute("value", "86400")
    
    # 将新节点追加到appSettings节点下
    $appSettings.AppendChild($newAddNode) | Out-Null
    
    # 保存修改后的配置文件
    $xml.Save($webConfigPath)
    Write-Host "已成功添加KillBitRefreshTimeInSeconds节点"
} else {
    Write-Host "KillBitRefreshTimeInSeconds节点已存在,无需重复添加"
}

# 重启IIS使配置生效(按需执行)
# iisreset

注意事项

  • 若操作ECP等其他Exchange虚拟目录的配置文件,需对应修改$webConfigPath的路径
  • 修改完成后建议重启IIS服务,确保配置生效
  • 操作前确认无其他进程正在修改该配置文件,避免保存失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 00:07:00