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 4534874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:20:07+00:00 2026-05-21T14:20:07+00:00

I am writing a powershell script to create and configure a number of websites

  • 0

I am writing a powershell script to create and configure a number of websites and virtual directories. I am using the .NET Microsoft.Web.Administration assembly. I have created a new application under the default website and added a new virtual directory to it and it all works well. What I’m trying to do now is set up the authentication options for the virtual directory. I am doing the following in powershell:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

$oIIS = new-object Microsoft.Web.Administration.ServerManager
$oWebSite = $oIIS.Sites["Default Web Site"]
$oApp = $oWebSite.Applications["/MyApp"]

$oConfig = $oApp.GetWebConfiguration()

$oAnonAuth = $oConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication")
$oAnonAuth.SetAttributeValue("enabled", "False")

However, the SetAttributeValue command gives me the following error:

“This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”

From what I have read elsewhere, there are some suggestions to change the XML file for the application to allow overriding. I don’t want to have to do that – is there any way to programmatically unlock the configuration to allow me to change it? I don’t want any user input into this process at all..

Thanks for any help,
Al.


Found the answer I was looking for – but being a new user I can’t answer my own question for 24 hrs..

I think I found the code below on this site, but my machine has since rebooted so I’ve lost the page. However, the following seems to work:

#
# Allow overriding of the security settings.
#
$oGlobalConfig = $oIIS.GetApplicationHostConfiguration()
$oConfig = $oGlobalConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Default Web Site/mySite")
$oConfig.OverrideMode="Allow"
$oIIS.CommitChanges()

#
# Following the commit above, we need a new instance of the configuration object, which we can now 
# modify.
#
$oGlobalConfig = $oIIS.GetApplicationHostConfiguration()
$oConfig = $oGlobalConfig.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Default Web Site/mySite")
$oConfig.SetAttributeValue("enabled", "False")
$oIIS.CommitChanges()
  • 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-21T14:20:07+00:00Added an answer on May 21, 2026 at 2:20 pm

    I wrote a blog post about this quite a while back. http://www.danielrichnak.com/powershell-iis7-teach-yoursel/

    The below code will loop through everything in system.webserver level and unlock it. You can target different nodes as you see fit.

    $assembly = [System.Reflection.Assembly]::LoadFrom("$env:systemroot\system32\inetsrv\Microsoft.Web.Administration.dll")
    
    # helper function to unlock sectiongroups
    function unlockSectionGroup($group)
    {
        foreach ($subGroup in $group.SectionGroups)
        {
            unlockSectionGroup($subGroup)
        }
        foreach ($section in $group.Sections)
        {
            $section.OverrideModeDefault = "Allow"
        }
    }
    
    # initial work
    # load ServerManager
    $mgr = new-object Microsoft.Web.Administration.ServerManager
    # load appHost config
    $conf = $mgr.GetApplicationHostConfiguration()
    
    # unlock all sections in system.webServer
    unlockSectionGroup(
         $conf.RootSectionGroup.SectionGroups["system.webServer"])
    

    Your solution is similar but different enough that I can’t verify what you’ve got, but since you say it works – sounds good. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a powershell script to deploy a number of reports to SQL Server
I'm writing a Powershell script and in it I'm using a hash table to
I'm writing a PowerShell script that will execute commands on a remote host using
I'm writing a PowerShell script that uses the SharePoint 2010 New-SPWeb cmdlet to create
I am writing a PowerShell script that will back up several folders from my
I'm writing a powershell script for deployment. I need to copy changed files from
I am writing a script for MS PowerShell. This script uses the Copy-Item command.
I'm writing a GUI tool using PowerShell that is able to do most AD
I'm getting a little frustrated on a little PowerShell script I'm writing. Basically I
I am writing a release script in powershell and need to invoke a custom

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.