Administrators sometimes need to perform all the tasks through PowerShell, and well-experienced windows administrators mostly prefer doing tasks through Windows Powershell. But make sure you must have administrative privileges to get started with managing services through Powershell.
In this article, you will learn about: How to Manage Windows Services with PowerShell?
List Services
A) If you would like to list all the services which are presently on your windows server, then run the following command in the Windows Powershell,
Get-Service
You can find following columns,
Status: You can find status of the service Stopped, Running.
Name: Exact name of the service.
DisplayName: The display name of the service.
B) Suppose, if you would like to list the service with its name, then use the following command,
Get-Service -name <service name>
Example: Get-Service -name ALG
C) Also, if you would like to list all the services starting with a specific letter or group of letters, use * as a wildcard character for a broad search.
Get-Service -name <starting-letter>*
Example: Get-Service -name se*
D) Incase, you do not know the exact name of the service, the use –DisplayName parameter with the command,
Get-Service -DisplayName <ServiceName>
Example: Get-Service -DisplayName “Secondary Logon”
Also, you can search multiple services at a time by seperating Display Names by comma (,).
Get-Service -DisplayName “ServiceName1”, “ServiceName2”, “ServiceName3”
Example: Get-Service -DisplayName “Secondary Logon”, “Sensor Service”
Start & Re-start Services
A) To Start specific service use -Name parameter and enter the service name accordingly with the start command,
Start-Service -Name <Service Name>
Example: Start-Service -Name SensorService
B) Some services are dependent on one or more than one service; for those services, the normal command won’t work because their dependent services might be at Stopped condition. First, list the dependent services using the following command,
get-service samss | Foreach { start-service $_.name -passthru; start-service $_.DependentServices -passthru}
Then, from the list, start all the dependent services using the following command,
Start-Service -Name <Service Name>
C) For some reason, you want to restart the service, then use following command,
Restart-Service -Name <Service Name>
Example: Restart-Service -Name SensorService
Stop, Suspend & Resume Services
A) To Stop specific service use -Name parameter and enter the service name accordingly with the start command,
Stop-Service -Name <Service Name>
Example: Stop-Service -Name SensorService
B) Some services are dependent on one or more than one service; for those services, the normal command won’t work because their dependent services might be in Running condition. For this situation, use -Force parameter to Stop command,
Stop-Service -Name <Service Name> -Force
Example: Stop-Service -Name SensorService -Force
Note: All the dependent services will also get stopped and may cause instability if you use one of those services.
C) For some reason, you want to suspend the service, then use the following command,
Suspend-Service -Name <Service Name>
Example: Suspend-Service -Name TermService
D) If you want to resume suspended services, then use the following command,
Resume-Service -Name <Service Name>
Example: Resume-Service -Name Netlogon