20

Using Set-Service, I'm able to change the StartType of my services between the accepted values of Boot, System, Automatic, Manual, Disabled. Using services.msc, I'm able to set some services to startup with a Priority of Automatic (Delayed Start). However, Get-Service still reports these delayed-start services as StartType : Automatic, and Set-Service errors out when attempting to set these values.

Am I able to set this property via powershell? Or am I limited to the UI or GPO?

Peter Vandivier
  • 373
  • 1
  • 2
  • 12

4 Answers4

21

No direct way in PowerShell, just use sc

sc.exe config NameOfTheService start= delayed-auto 

in older versions of Windows you needed a space after the equal sign, this doesn't seem to be required anymore but it still works.

You can also change the registry keys:

HKLM\SYSTEM\CurrentControlSet\Services\NameOfTheService\Start = 2
HKLM\SYSTEM\CurrentControlSet\Services\NameOfTheService\DelayedAutostart = 1
Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58
  • 1
    calling `sc.exe` directly makes it easy to pipe the result for later handling. as well - this answer gave me the idea to just query the registry directly with [`Get-ItemProperty`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-itemproperty) to determine if the service is DelayedAutostart. – Peter Vandivier Jul 06 '18 at 07:29
10

PowerShell 6.0 has added the option StartType to Automatic - Delayed in Set-Service cmdlet

ex: Set-Service -Name "Testservice" –StartupType "AutomaticDelayedStart"

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-service?view=powershell-6

Arun
  • 116
  • 1
  • 3
  • Worth noting that `Get-Service` still reports this as “Automatic” though. Thanks for the tip! Finally convinced me to stop sleeping on PSCore – Peter Vandivier Apr 03 '19 at 16:09
7

There is no simple way to do it using powershell cmdlets. In my opinion the easiest way is to use sc.exe. Here is one way to do that:

$myArgs = 'config "{0}" start=delayed-auto' -f 'TheServiceName'
Start-Process -FilePath sc.exe -ArgumentList $myArgs
EBGreen
  • 1,443
  • 11
  • 10
3

The catch is to use "StartupType" instead of "StartType" when you are searching for "AutomaticDelayedStart, which is introduced in PowerShell 6.

After a bit of trial and error and error, this worked for me:

Get-Service | Where-Object {$_.StartupType -eq "AutomaticDelayedStart"} | Sort-Object status
Ahmad Khan
  • 31
  • 1