Richard Ev
Richard Ev

Reputation: 54117

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?

Upvotes: 8

Views: 5328

Answers (4)

Avner
Avner

Reputation: 4556

If you get the error "There is no configuration defined for object at path IIS:\SslBindings" you need to set the PsPath parameter

-PSPath IIS:\Sites

Upvotes: 3

arcain
arcain

Reputation: 15270

I used this method:

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

Upvotes: 3

user2182089
user2182089

Reputation: 76

I had to add ssl to the value:

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

Upvotes: 6

Richard Ev
Richard Ev

Reputation: 54117

Solution found, using Set-WebConfiguration:

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

Upvotes: 3

Related Questions