Switch between Form/Windows authentication IIS using powershell

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Dragomir Dimitrov Dragomir Dimitrov 6 months, 4 weeks ago.

  • Author
    Posts
  • #39079
    Profile photo of Dragomir Dimitrov
    Dragomir Dimitrov
    Participant

    Hi every one. I got powershell script that create IIS pool/site now i need to make it switch between Forms/Windows auth. The problem is when i create it with forms auth i cant disable it so if i create new IIS with windows auth i have forms and windows auth and this is a problem.So my question is how i can disable forms auth using powershell.

  • #39080
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Hi Dragomir,

    Here is a nice example.

    http://forums.iis.net/t/1165277.aspx?How+can+I+use+a+powershell+script+to+modify+authentication

    and here is a reference to the names of the different authentication methods

    https://www.iis.net/configreference/system.webserver/security/authentication

  • #39107
    Profile photo of Dragomir Dimitrov
    Dragomir Dimitrov
    Participant

    already try this two suggestion but still i cant disable from auth if i create windows auth IIS site first

  • #39110
    Profile photo of Arie H
    Arie H
    Participant

    If you can share your script via gist or similar, we can try to see what's happening

  • #39116
    Profile photo of Dragomir Dimitrov
    Dragomir Dimitrov
    Participant

    i fix it to enable windows and disable forms auth
    $config = (Get-WebConfiguration system.web/authentication "IIS:\sites\$iisAppName")
    $config.mode = "Windows"
    $config | Set-WebConfiguration system.web/authentication
    Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -location $iisAppName/$iisAppPoolName

    to disable windows and enable forms
    $config = (Get-WebConfiguration system.web/authentication "IIS:\sites\$iisAppName")
    $config.mode = "Forms"
    $config | Set-WebConfiguration system.web/authentication

    $winAuth = Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication
    $winAuth.enabled = $false
    $winAuth | set-Webconfiguration -filter /system.webServer/security/authentication/windowsAuthentication -PSPath IIS:\ -location "$iisAppName"

You must be logged in to reply to this topic.