Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell where clause filtering

I am trying to filter services running in server using powershell script.But the syntax seems not in proper way

Script

Get-Service -ComputerName $ServerName |Where-Object {$_.Name -like "DEX*" -or $_.Name -like "WORLD*" -or $_.Name -like "Entr*"}

the highlighted section is having the problem.Any help is well appreciated..

like image 343
Renji Avatar asked Jan 27 '26 18:01

Renji


2 Answers

In Get-Service Name property match the short name of the service. Don't you need the DisplayName ?

Get-Service -ComputerName $ServerName |Where-Object {$_.DisplayName -like "DEX*" -or $_.DisplayName -like "WORLD*" -or $_.DisplayName -like "Entr*"}

Another thing, your services short or display names are really begining by WORLD or Entr ?

like image 147
JPBlanc Avatar answered Jan 29 '26 08:01

JPBlanc


Once you know you are looking for displayname, here is a shortest way :

 get-service -displayname DEX*,WORLD*,Entr*
like image 34
jojo Avatar answered Jan 29 '26 08:01

jojo