DSC, how to know if after running the configuration a reboot is required

So I'm using DSC Push mode

I have about 200 deployments per day to several environments (DEV/INT/QA/PROD)

Every time that I deploy I want to make sure that each server is configured correctly

So I'm running DSC automatically as part of my deployment which is executed totally without user interaction

So I would like to know if there's a way to know if after running the DSC configuration a reboot/restart is required

Basically after running this line

Start-DscConfiguration -Wait -Force -Path .\SomePath

Examples of how I'm configuring Packages

   Package MVC3
    {
        Name = "Microsoft ASP.NET MVC 3"
        Ensure = "Present"
        Path = "$Env:SystemDrive\AspNetMVC3ToolsUpdateSetup.exe"
        ProductId = "DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA"
        Arguments = "/q"
        DependsOn = "[WindowsFeature]IIS"
        Credential = $Credential
    }

   Package MVC4
    {
        Name = "Microsoft ASP.NET MVC 4 Runtime"
        Ensure = "Present"
        Path = "$Env:SystemDrive\AspNetMVC4Setup.exe"
        ProductId = "942CC691-5B98-42A3-8BC5-A246BA69D983"
        Arguments = "/q"
        DependsOn = "[Package]MVC3"
        Credential = $Credential
    }

Solution 1:

Something I've always used in the past is the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\ PendingFileRenameOperations registry value. If it's not empty - then you're pending a reboot. Note that the registry value should not even exist unless you are pending a reboot. It is deleted upon reboot. So if you don't see it that's why.

Edit: Also throw this key into the mix:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\UpdateExeVolatile

Those two keys together should tell you whether a reboot is pending or not.

Check this Microsoft article - even though the article is about Exchange, it clearly mentions how checking these two registry values is how Exchange knows whether a reboot is pending or not: http://technet.microsoft.com/en-us/library/cc164360(v=EXCHG.80).aspx

Edit October 29, 2014: Microsoft has released a new Desired State Configuration resource called xPendingReboot that will do a pretty good job at finding out if your system is pending a reboot or not. It does this by looking at the following list of registry keys:

$ComponentBasedServicing = (Get-ChildItem 'hklm:SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\').Name.Split("\") -contains "RebootPending"
$WindowsUpdate = (Get-ChildItem 'hklm:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\').Name.Split("\") -contains "RebootRequired"
$PendingFileRename = (Get-ItemProperty 'hklm:\SYSTEM\CurrentControlSet\Control\Session Manager\').PendingFileRenameOperations.Length -gt 0
$ActiveComputerName = (Get-ItemProperty 'hklm:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName').ComputerName
$PendingComputerName = (Get-ItemProperty 'hklm:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName').ComputerName
$PendingComputerRename = $ActiveComputerName -ne $PendingComputerName