Validate PowerShell DSC WaitFor

Michael Greene

This post is part four of a blog series introduced here: Validate the new features of PowerShell DSC.

New Capability

WaitFor is a new set of built-in configuration resources. Including the WaitFor resources in a configuration tells the configuration target machine that it should communicate with the Local Configuration Manager on a remote machine to verify that the remote has returned success, before the target machine continues its deployment. The WaitFor resources need to know which nodes to check, which DSC resource must complete successfully, how often to check, and how long to wait between checks.

WaitFor refers to 3 individual resources: WaitForAll, WaitForSome, and WaitForAny. The differences between the three resources:

    • WaitForAll – All nodes in the list most successfully complete Set for the given resource.


    • WaitForSome – Includes a property NodeCount to specify how many machines in the list must succesfully complete Set for the given resource before moving forward.
    • WaitForAny – If any node in the list successfully complete Set for the resource, move forward.

What is the purpose of this feature?

In complex service deployments sometimes one machine needs to pause deployment until another has completed work. Examples include a web server waiting for a database to be available, or a member server waiting for a domain controller to bring a new forest online.

What is the easiest way to test it?

Testing this feature requires more than one machine. Using the samples below, apply the first sample to a machine (\”first machine\”) that hosts a service or resource that the second machine depends upon, and the second sample to the machine (\”second machine\”) that must wait for the first machine configuration to be successful before continuing to apply its own configuration.

First machine:

Configuration TextFile    {        Import-DscResource -ModuleName 'PSDesiredStateConfiguration'            File TestFile        {             DestinationPath = \"C:\\TextFile\\test.txt\"           Contents = 'This is some text'        }    }    TextFile -out c:\\TextFile    Start-DSCConfiguration -path c:\\TextFile -verbose -wait


Second machine:

Configuration TextFile   {       Import-DscResource -ModuleName 'PSDesiredStateConfiguration'       WaitForAny FirstMachine        {            ResourceName = '[File]TextFile'           NodeName = 'FIRST MACHINE NAME'            RetryIntervalSec = 30            RetryCount = 30    }       File TestFile        {         DestinationPath = 'C:\\TextFile\\test.txt'           Contents = 'This is some text'        }    }  TextFile -out c:\\TextFile;     Start-DSCConfiguration -path c:\\TextFile -verbose -wait


What should I expect to see?

On the second machine, you should see the machine waiting for the first machine to complete its configuration, and once that occurs the second machine will continue its own configuration.

In the output below, the node is holding at Test unt il the remote machine confirms.

 Mode                LastWriteTime         Length Name                              ----                -------------         ------ ----                              -a----        6/26/2015   8:17 AM           2650 localhost.mof                     WARNING: The configuration 'TextFile' is loading one or more built-in resources     without explicitly importing associated modules. Add Import-DscResource -ModuleN   ame 'PSDesiredStateConfiguration' to your configuration to avoid this message.    VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.    VERBOSE: An LCM method call arrived from computer GREENEX1 with user sid S-1-5-2    1-124525095-708259637-1543119021-529543.    VERBOSE: [GREENEX1]: LCM:  [ Start  Set      ]  VERBOSE: [GREENEX1]: LCM:  [ Start  Resource ]  [[WaitForAny]FirstMachine]   VERBOSE: [GREENEX1]: LCM:  [ Start  Test     ]  [[WaitForAny]FirstMachine]



How to provide feedback

The introductory post in this series lists a summary of options for providing feedback. The best option is to use Microsoft Connect. Thank you so much for your time! It is sincerely appreciated.

Michael Greene Senior Program Manager ECG CAT Team; PowerShell & Automation



Discussion is closed.

Feedback usabilla icon