
Tengo una aplicación web instalada en c:\inetpub\wwwroot_Site1\AppName
la que tiene un grupo de secciones personalizado y una sección de la siguiente manera:
<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>
He escrito el siguiente fragmento de Powershell:
Import-Module WebAdministration
Get-WebConfiguration //Libraries IIS:\Sites\Site1\AppName
Que devuelve correctamente:
Nombre Secciones Grupos
==== ======== ===========
Bibliotecas Nombre.de.sección.personalizado
Nombre.de.sección.personalizado2
Lo que no puedo entender es cómo, ya sea a través de Get-WebConfiguration
u Get-WebConfigurationProperty
obtener acceso a los <add key="x" value="y" />
elementos que son hijos directos de CustomSectionName en el "cuerpo" real del archivo de configuración.
Respuesta1
Da la casualidad de que recientemente puse esta función en un marco web de PowerShell que escribo.
Aquí está el trío de líneas que necesitarás:
Add-Type -AssemblyName System.Web
$webConfigStore = [Web.Configuration.WebConfigurationManager]::OpenWebConfiguration($path)
$customSetting = $webConfigStore.AppSettings.Settings["$Setting"];
El tercero variará un poco dependiendo de lo que intentes conseguir.
Espero que esto ayude
Respuesta2
Si la aplicación web es del tipo SharePoint 2007, puede seleccionar una única configuración de aplicación desde su web.config a través de:
param ( [string] $url='http://contso.com')
[System.Reflection.Assembly]::LoadWithPartialName('System.Web') | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint') | Out-Null
[Microsoft.SharePoint.SPSite] $site = New-Object -TypeName 'Microsoft.SharePoint.SPSite' -ArgumentList $url
[System.Configuration.Configuration] $config = [System.Web.Configuration.WebConfigurationManager]::OpenWebConfiguration('/', $site.WebApplication.Name)
<p># pull the one appSetting string we're interested in
[string] $appSettingKey = 'avalidkey'
[string] $appSettingValue = $config.AppSettings.Settings[$appSettingKey].Value
Write-Host ("<appSetting> Key={0}, Value={1}" -f $appSettingKey, $appSettingValue)
$config = $null
$site.Dispose()
$site = $null