Author Posts

May 18, 2016 at 8:02 am

Sorry if the title sounds misleading but I don't know how else to describe the issue I'm having. Ok, so I'm using PS 5 on Windows 10 to create configurations for Windows 2012R2 servers that will pull from a Windows 2012R2 pull server. All machines have WMF 5 installed. I've got everything running fine except that DSC isn't putting everything from the config file into the MOF file. It is easier to see than explain, so below if my configuration script:

 Configuration ServerConfig 
    {
        Param()

        Node $allnodes.nodename 
        {

            File Temp 
            {
                DestinationPath = "C:\Temp"
	            Ensure = "Present"
	            Force = $True 
	            Type = "Directory"
            }#end File resource

            #region dynamically create resource configurations for each node
            $ConfigurationData.NonNodeData.Services.foreach
            (
                {
                    Service $_ 
                    {
                        Name = $_
                        StartupType = "Automatic"
                        State = "Running"
                    }
                }
            ) #foreach service

            #add defined features for all nodes
            $Node.features.foreach
            (
                { 
                    WindowsFeature $_ 
                    {
                        Name = $_
                        Ensure = "Present"
                    }
                }
            )#endregion
        } #end node

        #region dynamically create additional nodes
        #you will get errors if there are no matches
        Node $allnodes.Where({$_.role -eq 'FilePrint'}).Nodename 
        {
            WindowsFeature FileServices 
            {
                Name = "File-Services"
                Ensure = "Present"
            } 

            WindowsFeature PrintServices 
            {
                Name = "Print-Services"
                Ensure = "Present"
            } 
   
        } #close node

        Node $allnodes.Where({$_.role -eq 'Test'}).Nodename 
        {
            WindowsFeature DirectPlay 
            {
                Name = "Direct-Play"
                Ensure = "Present"
                IncludeAllSubFeature = $true
            } 
            WindowsFeature RemoteAsst 
            {
                Name = "Remote-assistance"
                Ensure = "Present"
                IncludeAllSubFeature = $true
            } 
        } #close node   
    } #close configuration

I'm using a .psd1 file for my Node data, so here is that file:

   @{
    #Node specific data
    AllNodes = @( 
       @{NodeName = "*";Features = @("Telnet-Client","Windows-Server-Backup")},
       @{NodeName = "Server-DSC01"; Role = "FilePrint"},
       @{NodeName = "Server-DSC02" ; Role = "Test"}
    )
    ;
    #non-node Specific data. No code allowed
    NonNodeData = @{Services = "bits","remoteregistry","wuauserv"}
}

The problem I'm having is that the info from the $ConfigurationData.NonNodeData.Services.foreach and $Node.features.foreach sections of the configuration don't show up in the MOF file and, thus, never get configured on the servrers. Its as if DSC completely ignores those sections, but I don't get any errors. It should be adding stuff that sets 3 services (bits, remoteregistry, and wuauserv) as well as stuff that installs Telnet and Server Backup on all nodes. This worked with PS 4 and DSC. I'm not sure what I'm doing wrong. Is there a different syntax for PS 5 with DSC?

May 18, 2016 at 10:18 am

You need to put '(' after foreach and not on newline.

Configuration ServerConfig 
    {
        Param()

        Node $allnodes.nodename 
        {

            File Temp 
            {
                DestinationPath = "C:\Temp"
	            Ensure = "Present"
	            Force = $True 
	            Type = "Directory"
            }#end File resource

            #region dynamically create resource configurations for each node
            $ConfigurationData.NonNodeData.Services.foreach(
            {
                    Service $_ 
                    {
                        Name = $_
                        StartupType = "Automatic"
                        State = "Running"
                    }
                }
            ) #foreach service

            #add defined features for all nodes
            $Node.features.foreach(
            { 
                    WindowsFeature $_ 
                    {
                        Name = $_
                        Ensure = "Present"
                    }
                }
            )#endregion
        } #end node

        #region dynamically create additional nodes
        #you will get errors if there are no matches
        Node $allnodes.Where({$_.role -eq 'FilePrint'}).Nodename 
        {
            WindowsFeature FileServices 
            {
                Name = "File-Services"
                Ensure = "Present"
            } 

            WindowsFeature PrintServices 
            {
                Name = "Print-Services"
                Ensure = "Present"
            } 
   
        } #close node

        Node $allnodes.Where({$_.role -eq 'Test'}).Nodename 
        {
            WindowsFeature DirectPlay 
            {
                Name = "Direct-Play"
                Ensure = "Present"
                IncludeAllSubFeature = $true
            } 
            WindowsFeature RemoteAsst 
            {
                Name = "Remote-assistance"
                Ensure = "Present"
                IncludeAllSubFeature = $true
            } 
        } #close node   
    } #close configuration

May 18, 2016 at 1:08 pm

Nitin,

Thanks for your reply. I made the change you suggested and I'm now seeing the info generated in the MOF files. Oddly, however, I still wasn't seeing the updates actually being applied to the servers. I had to delete the .mof and .mof.checksum files from the pull server, rerun the configuration and then the $Node.features.foreach WIndowsFeature settings finally were being applied. Still, the $ConfigurationData.NonNodeData.Services.foreach settings aren't being applied. One server is showing 2 of the services running but the 3rd is stopped. The other server is showing only 1 running with the other 2 stopped. Annoying to say the least.

May 18, 2016 at 1:20 pm

So DSC configuration completed without errors but you are still seeing some of the services in stopped state correct?
To troubleshoot can you manually run

Test-DscConfiguration -Detailed -verbose 

to get the information on the state of the system. This will at least give info on the resources DSC attempted to process.
You can also run

 Start-DscConfiguration -Existing -Verbose 

locally to check how DSC is processing the resources and whether it is skipping some resources for some reason.
There are some services that will stop automatically if they are not in use, so watch for them as well.

May 19, 2016 at 1:44 pm

Correct. I don't see any errors but some of the services don't start.
Here is what I'm seeing with Test-DSCConfiguration:

ERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]bits]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]bits]
VERBOSE: [MOS-DSC01]: [[Service]bits] Startup type for service 'bits' is 'Manual'. It does not match 'Automatic'.
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]bits] False in 0.2180 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]bits]
VERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]remoteregistry] False in 0.0160 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]wuauserv]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]wuauserv]
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]wuauserv] False in 0.0160 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]wuauserv]

For Start-DSCConfiguration -useexisting, I get:

ERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]bits]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]bits]
VERBOSE: [MOS-DSC01]: [[Service]bits] Startup type for service 'bits' is 'Manual'. It does not match 'Automatic'.
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]bits] False in 0.2180 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]bits]
VERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]remoteregistry] False in 0.0160 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]remoteregistry]
VERBOSE: [MOS-DSC01]: LCM: [ Start Resource ] [[Service]wuauserv]
VERBOSE: [MOS-DSC01]: LCM: [ Start Test ] [[Service]wuauserv]
VERBOSE: [MOS-DSC01]: LCM: [ End Test ] [[Service]wuauserv] False in 0.0160 seconds.
VERBOSE: [MOS-DSC01]: LCM: [ End Resource ] [[Service]wuauserv]

May 19, 2016 at 2:08 pm

Something is not right here, Start-DSCConfiguration -useExisting is detecting the change in the service type but Set method of the Service resource is not called. Ideally your logs should have had the following extra lines after '[ End Test ] [[Service]bits]' :
[ Start Set ] [[Service]bits]
[ End Set ] [[Service]bits]

Is that a copy/paste issue?