PowerShell: Add Custom Header to IIS Website Responses

Here’s a PowerShell snippet that will add a custom header to the response from a designated website using the Add-WebConfigurationProperty cmdlet:

Import-Module WebAdministration
Add-WebConfigurationProperty //system.webServer/httpProtocol/customHeaders  "IIS:\sites\MySuperWebsite" -AtIndex 0 -Name collection -Value @{name='Access-Control-Allow-Origin';value='*'}

The Add-WebConfigurationProperty cmdlet is part of the IIS WebAdministration module.

Hope this helps!

This entry was posted in PowerShell. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *