2013-02-14 89 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 :\站點