简体   繁体   English

如何使用 Powershell 删除 IIS 自定义标头?

[英]How do I remove IIS custom header using Powershell?

I am writing a powershell script that deploys a website to IIS 7. I would like to do the following command to remove a custom header using the Web-Administration module in powershell rather than with appcmd.我正在编写一个将网站部署到 IIS 7 的 powershell 脚本。我想执行以下命令来使用 powershell 中的 Web 管理模块而不是 appcmd 来删除自定义标头。 How do I do this command in powershell not using appcmd?如何在不使用 appcmd 的 powershell 中执行此命令?

appcmd set config /section:httpProtocol /-customHeaders.[name='X-Powered-By']

To remove the header on iis level: 要删除iis级别的标题:

Remove-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST  
                                -Filter system.webServer/httpProtocol/customHeaders 
                                -Name . 
                                -AtElement @{name='X-Powered-By'}

And for a specific site: 对于特定网站:

Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site'
                                -Filter system.webServer/httpProtocol/customHeaders
                                -Name .
                                -AtElement @{name='X-Powered-By'}

Adding a new custom field eg. 添加新的自定义字段,例如。 xff-ip to have remote client ip from x-forwarded-for request header xff-ipx-forwarded-for请求标头获得远程客户端ip

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -value @{logFieldName='xff-ip';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}

Or for a specific site: 或者针对特定网站:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='My Super Site']/logFile/customFields"  -name "." -value @{logFieldName='xff-ip';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}

Removing your added custom logging field eg. 删除添加的自定义日志记录字段 xff-ip

Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "."  -AtElement @{logFieldName='xff-ip'}

Or from your site only 或者仅限您的网站

Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='My Super Site']/logFile/customFields"  -name "." -AtElement @{logFieldName='xff-ip'}

Below script is working fine for default web site.以下脚本适用于默认网站。 My requirement is, first I want to check the list of sites and then remove the header from IIS level as well as site level.我的要求是,首先我想检查站点列表,然后从 IIS 级别和站点级别删除标题。

Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -Filter system.webServer/httpProtocol/customHeaders -Name . Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site' -Filter system.webServer/httpProtocol/customHeaders -Name 。 -AtElement @{name='X-Powered-By'} -AtElement @{name='X-Powered-By'}

Can you please share the script.能不能分享一下脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Powershell从http响应中删除IIS“服务器”标头? - How do I remove IIS 'server' header from http response using Powershell? 使用 Powershell 编辑 IIS 自定义响应标头 - Edit IIS Custom Response Header using Powershell 我必须使用Powershell中的Remove-WebConfigurationProperty指定什么“名称”参数来删除IIS定制错误? - What “Name” parameter must I specify to remove an IIS custom error using Remove-WebConfigurationProperty in Powershell? 如何使用 PowerShell 在 IIS 中设置 RapidFailProtectionInterval? - How do I set rapidFailProtectionInterval in IIS using PowerShell? 使用自定义错误页时删除IIS服务器标头 - Remove IIS Server header when using Custom Error Pages 如何在IIS中运行PowerShell脚本? - How do I run a PowerShell script “in” IIS? 使用 PowerShell 删除 IIS 自定义日志字段 - Remove IIS custom log field with PowerShell 如何让 IIS 从 WebApi 2 返回自定义缓存控件 Header,IIS 10 每次返回私有 - How do I get IIS to return a Custom-Cache Control Header from WebApi 2, IIS 10 returns private every time 如何使用Powershell将IIS7应用程序池及其设置导出到多个服务器 - How do I export IIS7 app pool and its settings using Powershell to multiple servers 如何使用PowerShell使用增量值设置一组IIS网站的绑定端口号? - How do I set the binding port number for a set of IIS websites with an increment value using PowerShell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM