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.
Start-DscConfiguration
throwing exceptions? If so, you can catch those and log relevant information. If it's too difficult to tell which node is being worked on, you might change your directory structure so that there's a directory for each node which contains its configuration. Then in code you iterate and callStart-DscConfiguration
for each node so that you can catch exceptions pertaining to an individual node.