使用PowerShell更改IIS SSL设置

时间:2017-08-01 08:55:52

标签: windows powershell iis ansible powershell-v2.0

我是Windows PowerShell的新手。 我正在尝试更改IIS的默认网站的SSL设置 Required SSL = false and client certificate = ignoreRequired SSL = true and client certificate = accept使用powershell(我必须将其配置为ansible playbook) 我搜索过但没有得到任何解决方案。

enter image description here

请帮助。任何线索或解决方案将不胜感激。 :) 谢谢

2 个答案:

答案 0 :(得分:9)

使用Set-WebConfiguration cmdlet。您可以使用一个很棒的configuration reference on IIS.NET来查找有效值 - 在这种情况下为SslSslNegotiateCert

Set-WebConfiguration -Location "[sitename]" -Filter 'system.webserver/security/access' -Value 'Ssl,SslNegotiateCert'

答案 1 :(得分:0)

实际上,Set-WebConfiguration没有以可靠的方式处理属性

你想要使用的是:

$cfgSection = Get-IISConfigSection -Location "{siteName}/{appName}" -SectionPath "system.webServer/security/access";
Set-IISConfigAttributeValue -ConfigElement $cfgSection -AttributeName "sslFlags" -AttributeValue "Ssl, SslNegotiateCert";

请注意,在使用 Set-IISConfigAttributeValue 后(并提交更改,如果您进行延迟提交),则不能使用 $cfgSection 的该实例进行后续更改;您必须先获取另一个实例。

PS:如果你想在弄乱它之前(或之后)查看配置中的内容,权威设置在这里:C:\Windows\System32\inetsrv\config\applicationHost.config

或者你可以继续上面的代码并添加Get-IISConfigAttributeValue -ConfigElement $cfgSection -AttributeName "sslFlags";