I have the following Powershell script which uses WMI to update the HTTP custom headers on a website in IIS 6.
The script seems to work fine, no errors generated, and the resultant $website object correctly shows the updated HttpCustomHeaders value. When I look at that site in IIS, though, the values have not been updated. This is also verified by visiting the site and looking at the headers in Firebug - the values are not saved.
Any ideas what I'm doing wrong?
$website = Get-WmiObject -Class IIsWebServerSetting -Namespace "root\microsoftiisv2" -ComputerName $computerName -filter "ServerComment = '$websiteName'" -Authentication 6 $headers = $webSite.HttpCustomHeaders $headers.Keyname = 'P3P: policyref="http://somewebsite.com/p3p.xml", CP="IDC DSP COR CUR DEV PSA IVA IVD CONo HIS TELo OUR DEL UNRo BUS UNI"' $headers.Value = $null $website.HttpCustomHeaders = $headers $website.Put()
I'm more than open to an alternative script that provides a better way of setting this value as above assumes there is already at least one header present.
I've also tried
Set-WmiInstance -InputObject $website instead of
$website.Put() but that made no difference.