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

标签 powershell iis windows-server-2016

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

system.webserver/security/access 的引用资料发现于 C:\Windows\System32\inetsrv\config\applicationHost.config这是使用 IIS 管理器时保存该复选框值的位置,给定网站的 SSL 设置:

<location path="MySite">
    <system.webServer>
        <security>
            <access sslFlags="Ssl" />
        </security>
    </system.webServer>
</location>

最佳答案

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

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

  • 首先,这不是我的默认 Windows 2016(从 aws 镜像加载)的一部分,因此我必须先执行 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force 来更新到 IISAdministration 1.1然后 Install-Module -Name IISAdministration -Force .您不能使用更新模块,因为 IISAdministration 1.0 没有随 NuGet 一起安装,它是 Win 2016 的一部分。
  • 二、SslFlag此属性与 SslFlags 无关对于 Require Ssl . SslFlagNew-IISSiteBinding可以设置为None, Sni, CentralCertStore .在IIS管理器中,相当于点击一个网站,然后右边的Bindings链接,然后Add/Edit,勾选“Require Server Name Indication”。

  • IIS 管理 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
    

    这些也可以通过管道传输。此 sslFlags 的可能值为:None、Ssl、SslNegotiateCert、SslRequireCert、SslMapCert、Ssl128(参见 Access Security access)

    关于powershell - 如何在 Windows 2016 上使用 Powershell IISAdministration 模块为 IIS 网站设置需要 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47909303/

    相关文章:

    powershell - Test-Path 是否有反向选项来输出无效路径?

    asp.net - 我的 asp.net 应用程序需要 "IIS Metabase and IIS 6 Configuration Compatibility"- 如何摆脱它?

    Azure AppInsight 不适用于静态文件应用程序

    windows-server-2016 - Radius 服务器未回复来自 Meraki AP 的访问请求

    wpf - Powershell 包 uri 对象

    .net - 如何判断 new-object 来自哪个版本的程序集?

    c# - WCF - 已添加具有相同键的项目

    ssl - IIS 缓存已删除的 SSL 证书

    docker - 由于 Hyper-V 组件之一未运行,无法启动虚拟机 'MobyLinuxVM'

    powershell - 如何将 get-childitem 的结果传递到命令中?