Filter Services When Get-Service Calls

I have done this in the past and cannot remember the correct command (I think I used instring or soemthign?)

I want to specify all running Windows services that have the word "sql" in it.

List of all Windows services:

Get-Service 

Is there an instring function that does this?

+4
source share
3 answers
 Get-Service -Name *sql* 

A longer alternative would be:

 Get-Service | where-object {$_.name -like '*sql*'} 

Many cmdlets offer built-in filtering and wildcard support. If you check the help files (Get-Help Get-Service -full), you will see

  -name <string[]> Specifies the service names of services to be retrieved. Wildcards are permitted. By default, Get-Service gets all of the services on the comp uter. Required? false Position? 1 Default value * Accept pipeline input? true (ByValue, ByPropertyName) Accept wildcard characters? true 

Typically, if filtering is built into the cmdlet, this is the preferred transition method because it is often faster and more efficient.
In this case, there may not be many performance benefits, but in V2, where you could pull services from a remote computer and filter, there would be a preferred method (less data to send back to the calling computer).

+15
source

You can get all the services that are running and have the words sql.

  Get-Service | Where-Object {$_.Status -eq "Running"} | Where-Object {$_.Name -like "*sql*"} 

If you need more information, see this (it doesn't matter) http://nisanthkv.blog.com/2012/06/29/get-services-using-powershell

Hope this helps ...

+4
source

Enter the command below:

 Get-Service -Name '*<search string>*' 
+2
source

All Articles