Create an IIS7 Web Application Using PowerShell with SSL Requirement for Require

I am building an IIS website using the PowerShell New-WebSite cmdlet, and in this web application using New-WebApplication .

SSL settings for the web application must be configured to require SSL; Require as shown below.

IIS SSL Settings

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

Requiring SSL is easy; you just add the -Ssl parameter to New-WebSite .

However, the only way we set the Require parameter is to use Appcmd.exe :

 & $env:SystemRoot\System32\inetsrv\Appcmd.exe ` set config "$WebSiteName/$VirtualDirName" ` /section:access ` /sslFlags:"SslRequireCert" ` /commit:APPHOST 

Is there an alternative to PowerShell?

+6
source share
4 answers

Solution found using Set-WebConfiguration :

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

I had to add ssl to the value:

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

+4
source

I used this method:

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

If you get the error "Configuration defined for an object on the IIS path: \ SslBindings", you need to set the PsPath parameter

-PSPath IIS: \ Sites

+1
source

All Articles