Set service StartType to Automatic - Delayed

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


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

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

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