Creating IIS7 web application using PowerShell with Require SSL set to "Require"
Asked Answered
I

4

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?

Isomeric answered 14/2, 2013 at 14:30 Comment(0)
E
6

I had to add ssl to the value:

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

Errancy answered 18/3, 2013 at 11:23 Comment(2)
The other options did nothing (including the -Ssl for new-website flag) - this worked fine (IIS 7.5, Windows Server 2008R2).Judenberg
What is the -Value if you want to either ignore or accept SSL?Tupi
I
3

Solution found, using Set-WebConfiguration:

Set-WebConfiguration -Location "$WebSiteName/$WebApplicationName" `
    -Filter 'system.webserver/security/access' `
    -Value "SslRequireCert"
Isomeric answered 14/2, 2013 at 16:29 Comment(2)
Has anyone ever received this error while running the above command: There is no configuration defined for object at path IIS:\SslBindings.Bioastronautics
I had the same error. Answer by arcain worked for me, but I had to remove <-name "sslflags"> part of itPrepotency
L
3

I used this method:

Set-WebConfigurationProperty -PSPath "machine/webroot/apphost" `
     -location "$mySiteName" -filter "system.webserver/security/access" `
     -name "sslflags" -value "Ssl,SslNegotiateCert,SslRequireCert"
Lucilla answered 26/3, 2014 at 7:0 Comment(0)
M
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

Mufti answered 10/4, 2014 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.