0

The following PowerShell command would give me a list of all windows services:

Get-WmiObject -Class Win32_Service

What if I want to use this object to display one certain service only? Lets say I want to use it to display the spooler service only. I don't want to use the Get-Service cmdlet. Thought Select-Object would help me, but that only selects property names, not names of services.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Jeff S.
  • 49
  • 8

2 Answers2

1
Get-WmiObject -Class win32_Service | Where-Object Name -eq 'spooler'

or

Get-WmiObject -Class win32_Service | Select-Object * | Where-Object Name -eq 'spooler'
Jez
  • 620
  • 1
  • 8
  • 13
  • Thanks! I also found out that this will basically give same result as your second example: `Get-WmiObject -Class win32_Service | Where-Object Name -eq 'spooler' | fl *` – Jeff S. Mar 22 '17 at 02:25
1

While filtering Get-WmiObject output with Where-Object will work, it will have a negative impact on performance if you run the cmdlet against remote hosts, because all output will be sent over the network before it's filtered on the local host. It's more efficient to filter directly with Get-WmiObject, so that only the relevant data is retrieved:

Get-WmiObject -Class Win32_Service -Filter "Name='spooler'"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328