Getting custom web.config sections and their contents in Powershell

Posted by Rob on Server Fault See other posts from Server Fault or by Rob
Published on 2011-11-16T09:13:17Z Indexed on 2011/11/16 10:00 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

I have a web application installed in c:\inetpub\wwwroot_Site1\AppName which has a custom section group and section as follows:

<configSections>
  <sectionGroup name="Libraries">
    <section name="Custom.Section.Name" type="System.Configuration.NameValueSectionHandler,system, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null"/>
    <section name="Custom.Section.Name2" type="System.Configuration.NameValueSectionHandler,system, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null"/>
  </sectionGroup>
</configSections>

I've written the following snippet of Powershell:

Import-Module WebAdministration

Get-WebConfiguration //Libraries IIS:\Sites\Site1\AppName

Which correctly returns:

Name         Sections                           Groups

====          ========                        ===========

Libraries    Custom.Section.Name

                  Custom.Section.Name2

What I can't fathom is how to, either via Get-WebConfiguration or Get-WebConfigurationProperty obtain access to the <add key="x" value="y" /> elements that are direct children of CustomSectionName in the actual "body" of the configuration file.

© Server Fault or respective owner

Related posts about iis

Related posts about powershell