How to get all Windows service names starting with a regular word?

There are several Windows services whose display name begins with a common name (here NATION). For example:

  • STATE CITY
  • NATION-STATE
  • STATE Village

Is there any team to get all services like "NATION-". Finally, I need to stop, start, and restart such services using the promt command.

+42
command-line command command-prompt windows-services
Dec 14 '12 at 12:41
source share
3 answers

Got:)

sc queryex type= service state= all | find /i "NATION" 
  • use /i for case insensitive search
  • the space after type= intentional and necessary
+99
Dec 28 '12 at 7:28
source share

Using PowerShell , you can use the following

 Get-Service | Where-Object {$_.displayName.StartsWith("NATION-")} | Select name 

This will display a list of all services whose name begins with "NATION -".

You can also immediately stop or start services;

  Get-Service | Where-Object {$_.displayName.StartsWith("NATION-")} | Stop-Service Get-Service | Where-Object {$_.displayName.StartsWith("NATION-")} | Start-Service 

or simply

  Get-Service | Where-Object {$_.displayName.StartsWith("NATION-")} | Restart-Service 
+14
Dec 14 '12 at 16:27
source share

Save it as a .ps1 file, and then run

powershell -file "path\to your\start stop nation service command file.ps1"

-2
May 10 '16 at 10:42
source share



All Articles