Created
July 22, 2021 15:39
-
-
Save jamesperrin/a04edb32745da95098e4473aecbc98b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
::################################################################################## | |
::# | |
::# Purpose: To configure HTTP Strict Transport Security (HSTS) Window Server versions 2019 with IIS 10. | |
::# OS: Window Server versions 2019 with IIS 10 | |
::# SEE: https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10-version-1709/iis-10-version-1709-hsts#iis-100-version-1709-native-hsts-support | |
::# | |
::# James Perrin, MIT License, https://www.countrydawgg.com, | @_jamesperrin | |
::# | |
::################################################################################## | |
#> | |
Import-Module IISAdministration | |
Reset-IISServerManager -Confirm:$false | |
Start-IISCommitDelay | |
$sitesCollection = Get-IISConfigSection -SectionPath "system.applicationHost/sites" | Get-IISConfigCollection | |
$siteElement = Get-IISConfigCollectionElement -ConfigCollection $sitesCollection -ConfigAttribute @{"name"="Default Web Site"} | |
$hstsElement = Get-IISConfigElement -ConfigElement $siteElement -ChildElementName "hsts" | |
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "enabled" -AttributeValue $true | |
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "max-age" -AttributeValue 31536000 | |
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "redirectHttpToHttps" -AttributeValue $true | |
Stop-IISCommitDelay | |
Remove-Module IISAdministration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment