如果我像这样在一个文件中嵌套DSCconfiguration,它工作正常:
Configuration Secondary { Param ($SomeParameter) Environment Test { Name = $SomeParameter Value = "12345" } } Configuration MyConfiguration { Node localhost { Secondary TheSecondary { SomeParameter = "TestEnvVar" } } } MyConfiguration Start-DscConfiguration .\MyConfiguration -Wait -Verbose
我想将我的configuration分成两个单独的文件。 一个将点对点来包含configuration。
Secondary.ps1:
Configuration Secondary { Param ($SomeParameter) Environment Test { Name = $SomeParameter Value = "12345" } }
Primary.ps1:
. .\Secondary.ps1 Configuration MyConfiguration { Node localhost { Secondary TheSecondary { SomeParameter = "TestEnvVar" } } } MyConfiguration Start-DscConfiguration .\MyConfiguration -Wait -Verbose
出于某种原因,这不会select传递到辅助configuration的参数,从而导致错误:
Could not find mandatory property Name. Add this property and try again. + CategoryInfo : ObjectNotFound: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : MI RESULT 6 + PSComputerName : localhost
看起来很奇怪,它在同一个文件中工作,而不是点源时。 我认为点源与在同一个文件中包含代码基本相同。 我在这里错过了什么?
如果要从另一个configuration中引用未在同一文件中定义的configuration,则需要使用复合资源模式。
在一个模块中,你将创build一个DscResources文件夹。 在该文件夹中,您将创build一个模块来保存您的复合configuration。 组合configuration将在具有扩展名.schema.psm1的文件中定义。 该文件将需要一个模块清单,指向作为根模块的schema.psm1文件。
有关更多详细信息和示例,请查看PowerShell团队博客 – http://blogs.msdn.com/b/powershell/archive/2014/02/25/reusing-existing-configuration-scripts-in-powershell-desired-国家configuration.aspx
Splatting的参数有助于 – 修改后的Primary.ps1应该可以工作:
. .\Secondary.ps1 Configuration MyConfiguration { Node localhost { $params = @{ SomeParameter = "TestEnvVar" } Secondary TheSecondary @params } } MyConfiguration Start-DscConfiguration .\MyConfiguration -Wait -Verbose