24

Currently, we have setup a .bat file which lists all services to start / stop them eg.

SC start SERVICE1
SC start SERVICE2

SC stop SERVICE1 SC stop SERVICE2

We add new services all the time and the list grows and is difficult to maintain in the batch file.

Is it possible to use a WILDCARD like 'SC start SERVICE*' or something?

Wolf
  • 416

3 Answers3

21

Easy, via Powershell:

Get-service SERVICE* | stop-service -force

Get-service SERVICE* | start-service
Excellll
  • 12,847
Gotxi
  • 209
20

You can use wmic and SQL-ish wildcard syntax.

From a cmd console:

wmic service where "name like 'SERVICE%'" call startservice

From a .bat script:

wmic service where "name like 'SERVICE%%'" call startservice

Available verbs include startservice, stopservice, pauseservice, resumeservice, and others. Do wmic service call /? for more info.

rojo
  • 633
  • 3
  • 9
2

if you want a One Line command,

You can use Restart-Service Cmdlet which is pre built in powershell.

To use Restart-Service simply call the cmdlet followed by the service name:

Restart-Service mysql57

To restart multiple services just specify the name of each service, separated by commas:

Restart-Service mysql57,apache

If you prefer, add the -displayname parameter and specify the service display name (the name shown in the Services snap-in) instead:

Restart-Service -displayname "Mysql 5.7 server"

This Cmdlet accepts wildcard matching as well. To restart all services starting with "mysql":

Restart-Service mysql*