2016-08-24 53 views
0

我正在嘗試編寫一個powershell腳本,我可以使用它在IIS中添加自定義http標題而不是手動添加它們。到目前爲止,我沒有在網上發現任何東西。有人可以請我指出正確的方向。使用powershell腳本添加自定義標頭

感謝

+0

像[這]( http://www.iis.net/configreference/system.webserver/httpprotocol/customheaders/add)(底部的代碼部分)? – wOxxOm

+0

Add-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST' -Name。 -Filter system.webServer/httpProtocol/customHeaders' -AtElement @ {name =「X-Frames-Options」;值='sameorigin'} –

+0

它只添加一個,但是當我嘗試添加多個同時它不起作用。 –

回答

2

我可以使用下面的成功添加2個或更多標題:

附加WebConfigurationProperty -PSPath機/ WEBROOT/APPHOST -Name . -Filter system.webServer/httpProtocol/customHeaders -AtElement @ {名稱=「X-Frames-選項「;值='sameorigin'}

Add-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST -Name . -Filter system.webServer/httpProtocol/customHeaders -AtElement @ {name =「Cache-Control」;值='私人,無緩存,無店鋪,最大年齡= 0}

1

作爲替代,避免了cmdlet和正在直登APPCMD仍然有效:

PS> C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webserver/httpProtocol /+"customHeaders.[name='myCustomName',value='myCustomValue']" 
+1

不是powershell cmdlet,但有助於瞭解在cmdlet不在特定系統上時appcmd.exe仍然存在。 –