我正在尝试使用xWebConfigKeyValue
DSC 模块的资源xWebAdministration
在我们的应用程序的 web.config 文件上设置多个值。这是我们配置的摘录,其中包含围绕 web.config 更改的主要活动:
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'
}
}
}
但是当我尝试运行配置时,出现以下错误:
Add-NodeKeys:键属性组合“C:\Company\ManagementPortal::AppSettings”与节点“myNode”中资源“xWebConfigKeyValue”的键“WebsitePath,ConfigSection”重复。请确保节点中每个资源的关键属性都是唯一的。在 line:160 char:9 + Add-NodeKeys $keyValues $keyNames $keywordName + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Write-Error], InvalidOperationException + FullyQualifiedErrorId : DuplicateKeyInNode,Add-NodeKeys
看到错误后,我查看了模块 schema.mof 文件,并注意到 appSettings 键不是配置的键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 to website location(IIS or WebAdministration format)")] String WebsitePath;
[Key, Description("Config Section to be update"), ValueMap{"AppSettings"}, Values{"AppSettings"}] String ConfigSection;
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Required, Description("Key for AppSettings")] String Key;
[Write, Description("Value for AppSettings")] String Value;
[Write, Description("If the given key value pair is for attribute, default is element")] Boolean IsAttribute;
};
由于只有站点路径和配置部分是键,因此我不能有多个资源实例指向同一个 appSettings 块但具有不同的 appSetting 键。那么如何配置多个 appSetting 键呢?