【发布时间】:2020-01-17 05:41:57
【问题描述】:
我正在编写要在 Azure DevOps 中使用的远程 PowerShell 脚本,该脚本用于编辑特定站点的 IIS HTTP 响应标头。下面的代码是添加它,但我缺少的是编辑现有的标题。
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") | Out-Null
$iis = new-object Microsoft.Web.Administration.ServerManager
$config = $iis.GetWebConfiguration("Test")
$httpProtocolSection = $config.GetSection("system.webServer/httpProtocol")
$customHeadersCollection = $httpProtocolSection.GetCollection("customHeaders")
$addElement = $customHeadersCollection.CreateElement("add")
$addElement["name"] = "X-Custom-Name"
$addElement["value"] = "xxx"
$customHeadersCollection.Add($addElement)
$iis.CommitChanges()
【问题讨论】:
标签: powershell iis azure-devops