Friday 15 January 2010

powershell - How do I set multiple AppSettings values using xWebConfigKeyValue? -



powershell - How do I set multiple AppSettings values using xWebConfigKeyValue? -

i'm trying utilize xwebconfigkeyvalue resource of dsc module xwebadministration set multiple values on our application's web.config file. excerpt our configuration main activities surrounding web.config changes:

configuration c4m { param( [parameter(mandatory)] [string] $builddroplocation ) import-dscresource -module xwebadministration node $allnodes.nodename { $managementportalinstallpath = 'c:\company\managementportal' file managementportalcontents { destinationpath = $managementportalinstallpath sourcepath = "$builddroplocation\managementportal" type = 'directory' recurse = $true } xwebconfigkeyvalue recaptchapublickey { websitepath = $managementportalinstallpath configsection = 'appsettings' key = 'recaptchapublickey' value = $node.recaptchapublickey dependson = '[file]managementportalcontents' } xwebconfigkeyvalue recaptchaprivatekey { websitepath = $managementportalinstallpath configsection = 'appsettings' key = 'recaptchaprivatekey' value = $node.recaptchaprivatekey dependson = '[file]managementportalcontents' } } }

but when seek run configuration, next error:

add-nodekeys : key properties combination 'c:\company\managementportal::appsettings' duplicated keys 'websitepath,configsection' of resource 'xwebconfigkeyvalue' in node 'mynode'. please create sure key properties unique each resource in node. @ line:160 char:9 + add-nodekeys $keyvalues $keynames $keywordname + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidoperation: (:) [write-error], invalidoperationexception + fullyqualifiederrorid : duplicatekeyinnode,add-nodekeys

after seeing error, took @ modules schema.mof file, , noticed appsettings key not key configuration @ c:\program files\windowspowershell\modules\xwebadministration\dscresources\msft_xwebconfigkeyvalue\msft_xwebconfigkeyvalue.schema.mof:

[classversion("1.0.0.0"), friendlyname("xwebconfigkeyvalue")] class msft_xwebconfigkeyvalue : omi_baseresource { [key, description("path website location(iis or webadministration format)")] string websitepath; [key, description("config section update"), valuemap{"appsettings"}, values{"appsettings"}] string configsection; [write, valuemap{"present","absent"}, values{"present","absent"}] string ensure; [required, description("key appsettings")] string key; [write, description("value appsettings")] string value; [write, description("if given key value pair attribute, default element")] boolean isattribute; };

since site path , config section keys, can't have multiple instances of resource pointing same appsettings block different appsetting keys. how can configure multiple appsetting keys then?

you can't configure 2 xwebconfigkeyvalue resources in same configuration because, you've found, resource key contains websitepath , configsection properties , doesn't discriminate on key property.

i think immediate options are:

create new cwebconfigkeyvalue resource module based on xwebconfigkeyvalue, , add together "key" attribute "key" property in "cwebconfigkeyvalue.schema.mof" prepare yourself.

or

define clashing resources in separate configuration blocks. i've had in project uses xservice resource.

neither of these particularly solution, might unblock until improve prepare comes along.

powershell dsc

No comments:

Post a Comment