2

I have written a Powershell script that should set a service to StatusType = 'Automatic'. But when I run the script it actually sets the StatusType = 'Automatic (Delayed Start) '. Below is my script:-

Set-Service -name 'XXXXX Data Import Service' -startupType automatic

Can anybody help me on setting the statusType to be just 'Automatic' ?

ED209
  • 588
  • 1
  • 9
  • 26
  • 1
    Unless the service is critical and **absolutely** needs to be run the moment the computer starts, using delayed start is preferable as it helps avoid the scramble for resources when multiple services all start. Delayed start services are queued and started one at a time so don't have such an impact on resources. – henrycarteruk Dec 07 '16 at 13:09

3 Answers3

1

Win 10 I suspect. You could not do it with set-service. Need to use sc.exe for explicit service startup state.

sc config "XXXXX Data Import Service" start= auto
autosvet
  • 869
  • 1
  • 9
  • 17
1

You can do it like this: See the Comments I have mentioned in the script. Use it accordingly.

#$server is the server name you want to change
#$service is the service name
$command = "sc.exe \\$server config $service start= delayed-auto" ## For delayed Auto
$command = "sc.exe \\$server config $service start= auto"## For Automatic
$output = invoke-expression -command $command
write-host $server " " $output

Notes: Space is important between start= delayed-auto.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
0

What worked me using Window Server 2016:

sc.exe config <service> start=auto

For example, sc.exe config aspnet_state start=auto

Notice that I did not need a space after the equals sign.

Elliott Beach
  • 10,459
  • 9
  • 28
  • 41