Home > database >  Hot to set Require SSL on IIS application by PowerShell
Hot to set Require SSL on IIS application by PowerShell

Time:12-14

Trying something like this:

$site = Get-IISSite |? Name -Match <...>
$app = $site.Applications |? Path -Match <...>
$app.SetAttributeValue('sslFlags', 'Ssl')

The fact is sslFlags still doesn't exists and apparently SetAttributeValue cannot add a new attribute because I get an error.

Exception while calling "SetAttributeValue" with "2" arguments: "Index not valid. (Exception from HRESULT: 0x80070585)"   (translated)

What's the correct way to do this?

CodePudding user response:

I recommend using app.exe instead. For example, I have a webapi(name:testapp) under "Default Web Site", Now I want to set the key "sslFlags" to "Ssl" in the powershell:

sslFlags is under section:system.webserver/security/access See Microsoft Doc

Then it worked.

By the way: I also tried with "Set-WebConfigurationProperty/Set-WebConfiguration/Set-IISConfigAttributeValue", but they didn't work well.

CodePudding user response:

After some investigation, I found the Powershell way to this by the new IISAdministration module should be something like:

$site = Get-IISSite |? Name -Match <...>
$service = $site.Applications |? Path -Match <...>
Get-IISConfigSection -Location $service -SectionPath "system.webServer/security/access" | Set-IISConfigAttributeValue -AttributeName sslFlags -AttributeValue Ssl

Can someone confirm?

  • Related