📜  powershell list services filter - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:33:46.655000             🧑  作者: Mango

PowerShell List Services Filter - Shell-Bash

PowerShell is a powerful command-line tool for automating tasks and managing system configuration on Windows systems. One of the common tasks that a system administrator might perform is listing and filtering services running on a server. In this article, we will introduce you to the PowerShell list services filter command, and show you how to use it effectively.

Syntax

The syntax for the PowerShell list services filter command is as follows:

Get-Service [-Name] <String[]> [-ComputerName <String[]>] [-DependentServices] [-Exclude <String[]>] [-Include <String[]>] [-RequiredServices] [-Status <ServiceControllerStatus[]>] [-DisplayName <String[]>] [-InputObject <ServiceController[]>] [-ServicesDependedOn <ServiceController[]>] [<CommonParameters>]
  • -Name: Specifies the name of the services to list. You can use a wildcard character (*) to match any characters in the name.
  • -ComputerName: Specifies the name of the remote computer to list services from.
  • -DependentServices: Retrieves the services that this service depends on.
  • -Exclude: Excludes the specified services from the list.
  • -Include: Includes only the specified services in the list.
  • -RequiredServices: Retrieves the services that depend on this service.
  • -Status: Specifies the status of the services to list. You can use the ServiceControllerStatus enumeration to specify the status (e.g. Running, Stopped, Paused, StopPending, StartPending).
  • -DisplayName: Specifies the display name of the services to list.
  • -InputObject: Specifies a service object to list.
Examples

Here are some examples of how to use the PowerShell list services filter command.

Example 1: List all services

To list all services running on the local computer, simply run the following command:

Get-Service
Example 2: List services by name

To list services that match a specific name, use the -Name parameter. For example, to list all services that contain the word "Windows" in their name, run the following command:

Get-Service -Name "*Windows*"
Example 3: List services by status

To list services that match a specific status, use the -Status parameter. For example, to list all services that are currently running, run the following command:

Get-Service -Status Running
Example 4: List services on a remote computer

To list services on a remote computer, use the -ComputerName parameter. For example, to list all services running on a computer named "server1", run the following command:

Get-Service -ComputerName server1
Example 5: List services by display name

To list services that match a specific display name, use the -DisplayName parameter. For example, to list all services that contain the word "Print" in their display name, run the following command:

Get-Service -DisplayName "*Print*"
Conclusion

The PowerShell list services filter command is a powerful tool for managing services on Windows systems. By using the various parameters available, you can quickly and easily list and filter services based on a wide range of criteria. Use this command in your PowerShell scripts to automate your service management tasks and improve your system administration workflow.