我目前正在建立一个实验室环境,以了解DSC可以实现什么以及限制在哪里.
我们需要根据操作系统,AD组成员资格和包含目标的OU等标准将一次性配置推送到节点组.
所以我开发了以下示例脚本:
- # Pulls computer objects from Active Directory
- Function Get-Nodes
- {
- Param($OperatingSystem)
- Get-AdComputer -Filter 'OperatingSystem -eq ${OperatingSystem}' -SearchBase "OU=SomeThing,DC=contoso,DC=com"
- }
- # Defines the configuration to apply
- Configuration ConfigureHostsPush
- {
- Node $Allnodes.NodeName
- {
- # This resource is not able to delete a key,only values
- Registry ConfigureRegistry
- {
- Ensure = "Present"
- Key = "HKEY_LOCAL_MACHINE\SOFTWARE\"
- ValueName = "MachineType"
- ValueData = "Hyper-V"
- }
- # This logs the defined message at the _destination_ host
- # within Microsoft->Windows->DesiredStateConfiguration->Analytic
- # requires showing and enabling the log first!
- Log LogSuccessfulRegistry
- {
- Message = "Successfully configued the defined registry value"
- DependsOn = "[Registry]ConfigureRegistry"
- }
- }
- }
- $nodes = Get-Nodes -OperatingSystem "Windows Server 2012 R2 Standard"
- # $nodes = Get-Nodes -OperatingSystem "Windows Server 2008 R2 Standard"
- # $nodes = Get-Nodes -OperatingSystem "Windows 7 Professional"
- # Pulls a list of nodes into a hash table
- $ConfigData = @{
- AllNodes = @(
- foreach ($node in $nodes)
- {
- @{NodeName = $node.Name}
- }
- )
- }
- # Generate the MOFs based on the configuration and hosts pulled from AD
- ConfigureHostsPush -ConfigurationData $ConfigData
- # Actually push out the configuration to the nodes
- Start-DscConfiguration -wait -Path D:\DATA\DSC\ConfigureHostsPush
但是,在我的情况下,某些节点并不总是可以访问并且处于脱机状态.我该如何进行错误处理和记录?所以我以后可以控制哪些节点成功配置或需要重新配置.
我知道我可以使用DSC日志资源,但这似乎非常有限,只能在LCM /目标节点端生成日志.