How to get all Windows service names starting with

2019-03-07 22:11发布

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.

3条回答
趁早两清
2楼-- · 2019-03-07 22:14

Save it as a .ps1 file and then execute

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

查看更多
【Aperson】
3楼-- · 2019-03-07 22:33

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
查看更多
干净又极端
4楼-- · 2019-03-07 22:34
sc queryex type= service state= all | find /i "NATION"
  • use /i for case insensitive search
  • the white space after type=is deliberate and required
查看更多
登录 后发表回答