Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

There are some windows services hosted whose display name starts with a common name (here NATION). For example:

  • NATION-CITY
  • NATION-STATE
  • NATION-Village

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

like image 427
Chandan Kumar Avatar asked Dec 14 '12 12:12

Chandan Kumar


People also ask

How do I get a list of services in Windows?

The services in Windows can be listed using the Service Manager tool. To start the Service Manager GUI, press ⊞ Win keybutton to open the “Start” menu, type in services to search for the Service Manager and press Enter to launch it. The services can also be listed using the command-line prompt (CMD) or the PowerShell.

How do I export a list of Windows services?

In the Services window, Action > Export... menu can give you the list as a . txt or . csv file.

What command do you do to list all services Windows?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. (Optional) Type the following command to view a list of all the services and press Enter: sc queryex state=all type=service.

How do I list all Windows services in PowerShell?

Using the Get-Service PowerShell cmdlet, you can generate a list of Windows Services running on your Windows 10/8/7 computer. Open an elevated PowerShell console, type Get-Service and hit Enter. You will see a list of all the Services installed on your Windows system.


2 Answers

sc queryex type= service state= all | find /i "NATION" 
  • use /i for case insensitive search
  • the white space after type=is deliberate and required
like image 96
Chandan Kumar Avatar answered Sep 19 '22 03:09

Chandan Kumar


Using PowerShell, you can use the following

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

This will show a list off all services which displayname starts with "NATION-".

You can also directly stop or start the 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 
like image 24
wimh Avatar answered Sep 21 '22 03:09

wimh