Getting custom web.config sections and their contents in Powershell
- by Rob
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.