Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4019962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:10:10+00:00 2026-05-20T10:10:10+00:00

I need to iterate all authentication modes for an IIS Application and disable all

  • 0

I need to iterate all authentication modes for an IIS Application and disable all except one.

something like:

foreach($itm in [collection of authentication modes for app]){
if([certain authentication]){enabled = true}else{enabled = false}}

I’m familiar with Set-WebConfigurationProperty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:10:10+00:00Added an answer on May 20, 2026 at 10:10 am

    You can iterate all native (as well as any installed third-party) authentication modes for the root web application for a given site by calling Get-WebConfiguration:

    $siteName = "MySiteName"
    
    $authentications = Get-WebConfiguration `
                       -filter "system.webServer/security/authentication/*" `
                       -PSPath "IIS:\Sites\$siteName"
    

    You can also iterate the authentication modes for any given web application in the site (or even specific file(s)). The following retrieves the authentication modes for a contrived web application called “\foo”:

    $authentications = Get-WebConfiguration `
                       -filter "system.webServer/security/authentication/*" `
                       -PSPath "IIS:\Sites\$siteName\foo"
    

    The SectionPath property can be used to examine the authentication mode, e.g.:

    $authentications | foreach {$_.SectionPath}
    

    Which outputs:

     /system.webServer/security/authentication/digestAuthentication
     /system.webServer/security/authentication/anonymousAuthentication
     /system.webServer/security/authentication/iisClientCertificateMappingAuthentication
     /system.webServer/security/authentication/basicAuthentication
     /system.webServer/security/authentication/clientCertificateMappingAuthentication
     /system.webServer/security/authentication/windowsAuthentication
    

    You might think you could do something as simple as this in your foreach loop…

     $authentications | `
     foreach { $_.Enabled = $_.SectionPath.EndsWith('\windowsAuthentication') }
    

    …but there’s a problem. It doesn’t work. It won’t actually fail with an error, but it won’t change anything either.

    That’s because authentication sections are locked. To change a setting in a locked section, you need to call Set-WebConfigurationProperty and include the -Location parameter, e.g.,

    Set-WebConfigurationProperty `
    -filter "/system.webServer/security/authentication/windowsAuthentication" `
    -name enabled -value true -PSPath "IIS:\" -location $siteName
    

    I suppose you can still pipe the objects to the foreach-object cmdlet but it’s probably going to be a lot easier to read (and maintain) if you script this using a foreach loop.

    $siteName = "MySiteName"
    
    $authentications = Get-WebConfiguration `
                       -filter "system.webServer/security/authentication/*" `
                       -PSPath "IIS:\Sites\$siteName"
    
    foreach ($auth in $authentications)
    {
         $auth.SectionPath -match "/windowsAuthentication$"
         $enable = ($matches.count -gt 0)
    
         Set-WebConfigurationProperty `
         -filter $auth.SectionPath `
         -name enabled -value $enable -PSPath "IIS:\" -location $siteName
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: something need here = scope.getConnections(); //getConnections() returns Collection<Set<IConnection>> I
I need to create feature which will iterate through all subsites of site collection
I have a 3D array in Python and I need to iterate over all
I have a property within a class, that I need to iterate through all
I have an table. I need to iterate, for each(datarow r in datatable.rows){ foreach(datacolumns
I need to iterate through all words of english dictionary & filter certain based
I need to iterate over all request header objects and print it in App
I have a need to iterate over all of the tables in my database.
Given a large N, I need to iterate through all phi(k) such that 1
I need to iterate over all elements in array in VBScript, but it's dimensions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.