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.

link|improve this question

75% accept rate
feedback

1 Answer

It just so happens that I recently put this function into a PowerShell web framework I write.

Here's the trio of lines you'll need:

Add-Type -AssemblyName System.Web
$webConfigStore = [Web.Configuration.WebConfigurationManager]::OpenWebConfiguration($path)              
$customSetting = $webConfigStore.AppSettings.Settings["$Setting"];   

The third will vary somewhat depending on what you're trying to get.

Hope this Helps

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.