8

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?

Richard Ev
  • 52,939
  • 59
  • 191
  • 278

4 Answers4

6

I had to add ssl to the value:

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

Abu Romaïssae
  • 3,841
  • 5
  • 37
  • 59
3

Solution found, using Set-WebConfiguration:

Set-WebConfiguration -Location "$WebSiteName/$WebApplicationName" `
    -Filter 'system.webserver/security/access' `
    -Value "SslRequireCert"
Richard Ev
  • 52,939
  • 59
  • 191
  • 278
  • 4
    Has anyone ever received this error while running the above command: There is no configuration defined for object at path IIS:\SslBindings. – B Johnson Aug 08 '13 at 17:49
  • I had the same error. Answer by arcain worked for me, but I had to remove <-name "sslflags"> part of it – MikhailSP Mar 06 '20 at 14:24
3

I used this method:

Set-WebConfigurationProperty -PSPath "machine/webroot/apphost" `
     -location "$mySiteName" -filter "system.webserver/security/access" `
     -name "sslflags" -value "Ssl,SslNegotiateCert,SslRequireCert"
arcain
  • 14,920
  • 6
  • 55
  • 75
3

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

Avner
  • 4,286
  • 2
  • 35
  • 42