How to search for the specific service in PowerShell?
https://www.tutorialspoint.com/how-to-search-for-the-specific-service-in-powershell
-
13-09-2020 - |
Domanda
How to search for the specific service in PowerShell?
You can get the specific service-related information using –name parameter and you just need to provide the service name.
Command
Get-Service –Name "Spooler"
Output
Status Name DisplayName ------ ---- ----------- Running Spooler Print Spooler
Command
Similarly, you can search for more than one service with the –name parameter.
Get-Service –Name "Spooler","RemoteAccess"
Output
Status Name DisplayName ------ ---- ----------- Stopped remoteaccess Routing and Remote Access Running Spooler Print Spooler
You can also use the wildcard character (*) in service name so the console can fetch the entire name.
When wildcard character (*) is used at the end of the name then debug console will check the starting string of the name and fetch all the services which start with that particular string.
Get-Service –Name "Spoo*","RemoteAccess"
Command
When wildcard character (*) is used at both the ends then the debug console will check if the part of that string contains in the service name then it will fetch related services.
Get-Service –Name "*management*”
Output
Status Name DisplayName ------ ---- ----------- Stopped AppMgmt Application Management Running DellClientManag... Dell Client Management Service Stopped DmEnrollmentSvc Device Management Enrollment Service Stopped dmwappushservice Device Management Wireless Applicat... Stopped EntAppSvc Enterprise App Management Service Running LMS Intel(R) Management and Security Ap... Running RmSvc Radio Management Service Stopped TieringEngineSe... Storage Tiers Management Running Winmgmt Windows Management Instrumentation Stopped WinRM Windows Remote Management (WS-Manag... Stopped WManSvc Windows Management Service Stopped XboxGipSvc Xbox Accessory Management Service
You can also use Where-Object command with a comparison operator to search the above results.
Example
For example, we need to find the service name Spooler.
Get-Service | Where-Object{$_.Name -eq "Spooler"}
Output
Status Name DisplayName ------ ---- ----------- Running Spooler Print Spooler
With the wildcard character (*) but here you need to use comparison operator –like instead of -eq
Get-Service | Where-Object{$_.Name -like "Spoo*"} Status Name DisplayName ------ ---- ----------- Running Spooler Print Spooler
Example
Wildcard character (*) at both ends.
Get-Service | Where-Object{$_.Name -like "*management*"}
Output
Status Name DisplayName ------ ---- ----------- Stopped AppMgmt Application Management Running DellClientManag... Dell Client Management Service Stopped DmEnrollmentSvc Device Management Enrollment Service Stopped dmwappushservice Device Management Wireless Applicat... Stopped EntAppSvc Enterprise App Management Service Running LMS Intel(R) Management and Security Ap... Running RmSvc Radio Management Service Stopped TieringEngineSe... Storage Tiers Management Running Winmgmt Windows Management Instrumentation Stopped WinRM Windows Remote Management (WS-Manag... Stopped WManSvc Windows Management Service Stopped XboxGipSvc Xbox Accessory Management Service