Configuring IIS with Powershell - Activating Form Authentication

My IIS looks like this:

Sites -> Default Web Site -> MyWebApp 

Then the question arises: how to enable authentication on MyWebApp? I can change or change Anonymous access, Basic and Windows Auth. However, Forms Auth is not so simple. How to do it in Powershell?

I can read the setup like this:

(Get-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site\MyWebApp').Mode

I am having problems or not luck in Set-Webconfiguration or Set-Webconfigurationproperty. I find these cmdlets difficult to understand.

Changes occur in web.config, at least updating web.config, when I click "Enable" or "Disable" in "Form Authentication" in IIS Manager. Any hints and tips are highly appreciated.

+4
source share
2 answers

You pass the authentication configuration settings to Set-Webconfiguration, providing the appropriate filter after changing your properties:

 $config = (Get-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site') $config.mode = "Forms" $config | Set-WebConfiguration system.web/authentication 

Note. Save the configuration before attempting to do this.

+2
source

Or with one insert:

 Set-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site' -value @{mode='Forms'} 
+2
source

Source: https://habr.com/ru/post/1441929/


All Articles