Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all service names matching a string pattern

I'm trying to display the name (just the name) of all of the installed services that contain the string "SQL". For example, I want to see

  • SQLAgent$SQL2008_R2
  • SQLBrowser
  • SQLWriter

So I try this:

Get-WmiObject Win32_Service

This displays all of the services, but as a list.

Exit Code : 0
Name      : ProtectedStorage
ProcessId : 664
StartMode : Manual
State     : Running
Status    : OK

Exit Code : 1077
Name      : QWAVE
ProcessId : 0
StartMode : Manual
State     : Stopped
Status    : OK
(etc...)

This is good, but I just want to see the name. So I type:

Get-WmiObject Win32_Service | select-object Name

And I get what I expect:

sppuinotfy
SQLAgent$SQL2008_RT
SQLBrowser
SQLWriter
SSDPSRV
(etc ..)

All is good. I take the next step of filtering the names to only include SQL related ones:

Get-WmiObject Win32_Service | select-object Name | select-string -pattern 'SQL'

And now it's confusing. Here is my output:

@{Name=BcmSqlStartupSvc}
@{Name=MSOLAP$SQL2008_R2}
@{Name=MSSQL$SQL2008_R2}
(etc ...)

Why am I getting this output, instead of just the names? What should I be typing to get just the names?

like image 411
Andrew Shepherd Avatar asked Jan 19 '11 02:01

Andrew Shepherd


1 Answers

You can use Get-Service instead of get-WMIObject and do it like this"

get-service sql* | select -expand name
like image 164
mjolinor Avatar answered Oct 18 '22 16:10

mjolinor