6

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
    }
Jupaol
  • 273
  • 4
  • 10
  • The puppetlabs reboot modules scans a bunch of well known registry locations to attempt to detect if a reboot is required. Take a look at the [reboot.rb](https://github.com/puppetlabs/puppetlabs-reboot/blob/master/lib/puppet/provider/reboot/windows.rb) to see the locations that are examined. You could develop a powershell script to perform the same checks and trigger a reboot. – Zoredache Mar 17 '14 at 22:02

1 Answers1

6

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
Ryan Ries
  • 55,011
  • 9
  • 138
  • 197
  • I will try this. Although I was hoping DSC to provide me a way to know if a restart is required. I mean they do if I run the command with the -Verbose flag but that only displays it on the screen. I was trying to find like a bool flag or something from DSC. – Jupaol Mar 18 '14 at 15:02
  • @Jupaol They just released a new Powershell DSC resource just for you. – Ryan Ries Oct 29 '14 at 14:05
  • Ohh that's awesome, I will check it out, thank you for the update – Jupaol Oct 29 '14 at 20:21