Filter the output of a command as if it was text

Viewed 85332

I have a simple question, but I am also a beginner in PowerShell. I think it has to do with the fact that the output of the Get-Process command (alias ps) is objects and not text.

I want to get a list of the services running that have the name "sql" in them.

This is what I tried so far, but every attempt returns nothing:

Get-Service | where {$_ -match 'sql'}

Get-Service | where {$_ -like 'sql'}

Get-Service | Select-String sql

I am looking for a pattern that lets me treat the output of every command as searchable text.

10 Answers

If you want to list all services with "sql" in the service name, just use:

 get-service -name *sql*

how about:

Get-Service| Out-String -stream | Select-String sql

where the key point is that -stream option converts the Out-String output in separate lines of text.

Related