Windows Services in Powershell
List Windows Services
To get a list of services, run the following command:
Here’s a list of my first 10 services:
Getting a list of services from a remote machine:
Filtering Services
You have a few options when trying to filter the list of services. You can use Get-Service arguments or send the output to be filtered - note we’re filtering the service Name, not the service DisplayName:
To filter on display name with wildcards, specify the -DisplayName argument explicitly:
Each service is a powershell object, so you can always pipe the content to a filter. Below we’re looking for any items that have the Name of Dhcp or WinRM. Note we’re using the Where-Object and evaluating the Name against a Regex collection by using -match command.
Starting and Stopping Services
To start or stop a service use the Start-Service and Stop-Service cmdlets.
Find the Services you wish to start. Use the filtering to find a single instance. If there are multiple services and you pipe them to Start-Service or Stop-Service, they’ll all be started or stopped. If an error occurs for one service (e.g. it cannot start), the error will be reported to the console, but the rest of the services will be sent and attempted to be started.
Finding all services with web in the name:
Piping the services to Stop-Service:
Chaining up more filtering and passing the services though the pipeline to Start-Service: