如何在 Windows 2016 上使用 Powershell IISAdministration 模块为 IIS 网站设置需要 SSL

Thi*_*y_S 5 iis powershell windows-server-2016

在 Windows 2016 上,尝试将新的 IISAdministration 模块用于 Powershell(而不是 WebAdministration),您如何设置Require Ssl特定网站的复选框?

参考了system.webserver /安全/访问中发现,C:\Windows\System32\inetsrv\config\applicationHost.config这也正是该复选框值使用IIS管理器,SSL设置时为某个网站保存的:

<location path="MySite">
    <system.webServer>
        <security>
            <access sslFlags="Ssl" />
        </security>
    </system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)

Thi*_*y_S 7

为后代回答我自己的问题。

IISAdministration 的New-IISSiteBinding cmdlet 让我很困惑。

  1. 首先,这不是我默认的 Windows 2016(从 aws 映像加载)的一部分,所以我必须先更新到 IISAdministration 1.1 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force,然后Install-Module -Name IISAdministration -Force. 您不能使用 Update-Module,因为 IISAdministration 1.0 未随 NuGet 一起安装,它是 Win 2016 的一部分。

  2. 其次,SslFlagthis 上的属性与SslFlagsfor无关Require SslSslFlagNew-IISSiteBinding可以设置为None, Sni, CentralCertStore。在IIS管理器中,相当于点击一个网站,然后点击右边的Bindings链接,再点击Add/Edit,勾选“Require Server Name Indication”。

需要 IISAdministration cmdlet Get-IISConfigSection。以下代码Require Ssl在网站上设置(相当于在 IIS 管理器中单击网站,然后单击 SSL 设置图标,“需要 SSL”复选框):

Import-Module IISAdministration
$ConfigSection = Get-IISConfigSection -SectionPath "system.webServer/security/access" -Location "MyWebSite"
#to set:
Set-IISConfigAttributeValue -AttributeName sslFlags -AttributeValue Ssl -ConfigElement $ConfigSection
#to read:
Get-IISConfigAttributeValue -ConfigElement $ConfigSection -AttributeName sslFlags
Run Code Online (Sandbox Code Playgroud)

这些也可以通过管道传输。此 sslFlags 的可能值为:None、Ssl、SslNegotiateCert、SslRequireCert、SslMapCert、Ssl128(请参阅访问安全访问