1

I've recently noticed that our Windows Server 2016 VMs on Azure sometimes fail to start some of their services after rebooting the system (for example ADFS, Remote Desktop Broker and others) even though they're set to Automatic and I've set the recovery options to restart the service in case of failure. This happens even when a long period of time has passed since the reboot, so it's not a matter of waiting. When I go and start the service manually it works fine.

What I'd like to do is use PowerShell DSC to ensure that every service that has a startup type set to Automatic / Automatic Delayed is always running. I found the following blog post which explains how to do this for an individual service, but how would I go about doing it for ANY service that has the startup set to Automatic?

I found another useful post here but it's a regular PowerShell script and I'd like to do that with DSC instead.

Thank you.


Update: I've used the following DSC Script resource:

SetScript = {
            $service = Get-WmiObject -Class Win32_Service -Filter "startmode = 'auto' AND state != 'running'"
            foreach ($svc in $service)
                {
                    Start-Service $svc.Name
                }
        }
TestScript = {
            $service = Get-WmiObject -Class Win32_Service -Filter "startmode = 'auto' AND state != 'running'"
            if ($null -eq $service)
                {
                    return $true
                }
            else
                {
                    return $false
                }
        }
  • 1
    You probably don't want to do this for *all* Automatic services. There are a number of them that are set to Automatic startup, but stop on their own by design and have triggers to start as necessary. – Ryan Bolger Sep 05 '18 at 17:08
  • @RyanBolger is correct. At best, you'll waste compute time. At worst, you may make the system unstable. You'd do well to only do this for specific services you know are causing problems if stopped, and do your best to figure out why they aren't running in the first place. – Matthew Wetmore Sep 09 '18 at 08:45

1 Answers1

0

You cant do that with powershell dsc unless you use a script step or a list of services.

4c74356b41
  • 628
  • 5
  • 10