简体   繁体   English

使用PowerShell创建IIS7 Web应用程序,并将SSL设置为“Require”

[英]Creating IIS7 web application using PowerShell with Require SSL set to “Require”

I'm creating an IIS web site using PowerShell's New-WebSite cmdlet, and within that a web application using New-WebApplication . 我正在使用PowerShell的New-WebSite cmdlet创建一个IIS网站,并使用New-WebApplication一个Web应用程序。

The SSL settings for the web application need to be set to Require SSL; Web应用程序的SSL设置需要设置为Require SSL; Require as shown below. 要求如下所示。

IIS SSL设置

For consistency, I would like to do this using only PowerShell cmdlets. 为了保持一致性,我想仅使用PowerShell cmdlet执行此操作。

The Require SSL setting is easy; 要求SSL设置很简单; you just add the -Ssl parameter to New-Website . 您只需将-Ssl参数添加到New-Website

However, the only way we've found to set the Require option is using Appcmd.exe : 但是,我们发现设置Require选项的唯一方法是使用Appcmd.exe

& $env:SystemRoot\System32\inetsrv\Appcmd.exe `
    set config "$WebSiteName/$VirtualDirName" `
    /section:access `
    /sslFlags:"SslRequireCert" `
    /commit:APPHOST

Is there a PowerShell alternative to this? 有PowerShell替代品吗?

I had to add ssl to the value: 我不得不在值中添加ssl

Set-WebConfiguration -Location "$WebSiteName/$WebApplicationName" -Filter 'system.webserver/security/access' -Value " Ssl , SslRequireCert" Set-WebConfiguration -Location“$ WebSiteName / $ WebApplicationName”-Filter'system.webserver -Filter 'system.webserver/security/access' access'-Value“ Ssl ,SslRequireCert”

Solution found, using Set-WebConfiguration : 使用Set-WebConfiguration找到解决方案:

Set-WebConfiguration -Location "$WebSiteName/$WebApplicationName" `
    -Filter 'system.webserver/security/access' `
    -Value "SslRequireCert"

I used this method: 我用这个方法:

Set-WebConfigurationProperty -PSPath "machine/webroot/apphost" `
     -location "$mySiteName" -filter "system.webserver/security/access" `
     -name "sslflags" -value "Ssl,SslNegotiateCert,SslRequireCert"

If you get the error "There is no configuration defined for object at path IIS:\\SslBindings" you need to set the PsPath parameter 如果您收到错误“没有为路径IIS中的对象定义配置:\\ SslBindings”您需要设置PsPath参数

-PSPath IIS:\\Sites -PSPath IIS:\\ Sites

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM