2013-02-14 42 views
6

我创建使用PowerShell的New-WebSite cmdlet的IIS网站,并在一个web应用程序中使用New-WebApplication IIS7的Web应用程序。创建使用PowerShell工具要求SSL设置为“要求”

Web应用程序的SSL设置需要设置为需要SSL;如下所示需要

IIS SSL Settings

为了保持一致性,我想做到这一点只使用PowerShell命令。

要求SSL设置很容易;您只需将-Ssl参数添加到New-Website即可。

然而,我们发现,设置要求选择是使用Appcmd.exe的唯一途径:

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

是否有PowerShell的替代品呢?

回答

2

发现的解决方案,使用Set-WebConfiguration

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

运行上述命令而有没有人接收此错误:没有在路径对象定义配置IIS:\ SslBindings。 – 2013-08-08 17:49:50

4

我不得不添加SSL的值:

设置-WebConfiguration -Location “$ WebSiteName/$ WebApplicationName” -Filter 'system.webserver/security/access' - 值 “SSL,SslRequireCert”

+0

其他选项什么也没做(包括-ssl对新网站的标志) - 此工作的罚款(IIS 7.5和Windows Server 2008 R2)。 – geographika 2013-11-13 15:51:15

1

我用这个方法:

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

如果你得到的错误“有没有在路径对象定义配置IIS:\ SslBindings”你需要设置PsPath参数

-PSPath IIS :\站点