Switch between Form/Windows authentication IIS using powershell

This topic contains 4 replies, has 3 voices, and was last updated by  Dragomir Dimitrov 2 years, 1 month ago.

  • Author
  • #39079

    Dragomir Dimitrov

    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

    Curtis Smith

    Hi Dragomir,

    Here is a nice example.


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


  • #39107

    Dragomir Dimitrov

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

  • #39110

    Arie H

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

  • #39116

    Dragomir Dimitrov

    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.