I am currently building a lab environment to get a feeling on what DSC can accomplish and where the limits are.
We have a requirement to push out one-shot configurations to group of nodes based on criterias like operating system, AD group membership and OUs containing the targets.
So I developed the following exemplary script:
# 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
However some of the nodes are not always reachable and are offline in my case. How should I do the error handling and logging? So I can later on control which nodes got successfully configured or needs reconfiguration.
I know I can use the DSC log resource, but that seems to be pretty limited and only generates logs on the LCM/target node side.