【发布时间】:2020-07-30 14:38:38
【问题描述】:
在 PowerShell 中,我试图列出所有没有特定名称和值组合的 HTTP 响应标头。
具体来说:
名称不是“X-Powered-By”且值不是“ASP.NET”
我设法通过使用this solution 取得了一些进展,但我无法查询我想要的值的结果:
$iisWebsiteName = "Default Web Site"
$IISManager = new-object Microsoft.Web.Administration.ServerManager
$IISConfig = $IISManager.GetWebConfiguration($iisWebsiteName)
$httpProtocolSection = $IISConfig.GetSection("system.webServer/httpProtocol")
$customHeadersCollection = $httpProtocolSection.GetCollection("customHeaders")
$customHeader = $customHeadersCollection | Select-Object rawattributes | Select-Object -Expand *
这是我得到的回应:
X-Powered-By
Referrer-Policy
ASP.NET
no-referrer
我不知道如何查询此输出并获取相关项目,或者我什至是否以正确的方式进行调查。
【问题讨论】:
-
如果您说您只需要这两个字符串,那么只需使用 Select-String cmdlet 或正则表达式匹配来选择它们以仅获取您想要的那些或删除您不想要的那些或选择数组位置。
-
这很有意义,但是 Value 和 Name 不是成对出现的,而是作为连续的项目。
标签: powershell iis