Search code examples
ssliis-7powershell-2.0appcmd

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.

The SSL settings for the web application need to be set to Require SSL; Require as shown below.

IIS SSL Settings

For consistency, I would like to do this using only PowerShell cmdlets.

The Require SSL setting is easy; you just add the -Ssl parameter to New-Website.

However, the only way we've found to set the Require option is using 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?


Solution

  • I had to add ssl to the value:

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