'Trying to use PowerShell DSC inside of MDT Task Sequence - how to handle reboots?

I am trying to use DSC push config inside of MDT, and currently running into a few issues. Here is kind of my thought process around this:

Because I am doing a "whole server configuration" for a pretty complex config, the LCM is going to require multiple reboots.

I want to make sure that I depend upon the LCM to communicate to MDT that a reboot is required, after which MDT will reboot the server and re-run the configuration.

I'd like for the configuration to continue in spite of any warnings or failures. The BDD.log will show what these are, so that the person provisioning the server can see what failed and either fix it in the code, or just fix it after the fact.

I think that there is some method of using $TSenv:SMSTSRetryRequested and $TSenv:SMSTSRebootRequested

What I've tried so far is something along these lines, however this didn't work:

if ((Get-DscConfigurationStatus).RebootRequested -eq $true) {
    $TSenv:SMSTSRebootRequested = $true
    $TSenv:SMSTSRetryRequested = $true 
} 
else {
    $TSenv:SMSTSRebootRequested = $false
    $TSenv:SMSTSRetryRequested = $false
}

Now what ends up happening here, is that the configuration goes as expected. On every reboot, it will check through existing resources and then start on new ones further down in the configuration, even if there are failures.

But for some reason, it seems that MDT thinks that a reboot is always requested, even if it gets all the way to the end of the configuration. Mind you, there always seem to be failures here and there during the DSC apply phase, so perhaps that's the problem? Otherwise, maybe the $TSenv variables are persisting through the reboots?

I also do know that there is a way inside of the DSC configuration to tell the LCM how to process reboots, but I'm not quite sure how to use that resource or where to put it, or if it will solve my problem. It's my next step, but I wanted to post here to see if anybody has any thoughts or has done something like this before.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source