Service stopped? Restart it with PowerShell

In a previous article, I discussed changing a Windows Service Log On Account information using the Set-Service PowerShell cmdlet. Just as the Set-Service cmdlet modifies the properties of a Windows Service, the Get-Service cmdlet gets a Windows Service properties.


Running the Get-Service cmdlet without any parameters will list the Status,  Name, and DisplayName of each service on a system. Using the Get-Service cmdlet with a combination of parameters lists the services that match the criteria.
Return a list of Services that start with the Name Microsoft:
Get-Service -Name "Microsoft*"
Return a list of Services that begin with Microsoft and do not contain WS:
Get-Service -Name "Microsoft*" -Exclude "*WS*" | Format-Table -Property Name, Status, StartType, DisplayName
Note: You can use the PowerShell Format Commands to change the output view.
Return a list of Services with a Name that begins with Microsoft and a Status of Stopped:
Get-Service -Name "Microsoft*" | Where-Object {$_.Status -eq "Stopped"} | Format-Table -Property Name, Status, StartType, DisplayName
The Set-Service cmdlet modifies service properties, and the Status is one of those properties.
Start the Service with a Name MicrosoftDynamicsNavWS:
Set-Service -Name MicrosoftDynamicsNavWS -Status Running 
The service list returned from the Get-Service cmdlet may be piped to the Set-Service cmdlet to restart a stopped service. In this example, services that begin with MicrosoftDynamicsNAV and have a Stopped status pass to the Set-Service cmdlet to start:
Get-Service -Name "MicrosoftDynamicsNav*" | Where-Object {$_.Status -eq "Stopped"} | Set-Service -Status Running

The stopped services with a name beginning with MicrosoftDynamicsNav start on the machine, unless there is something preventing the service from starting.

Note: The code and information discussed in this article is for informational and demonstration purposes only. 

Permanent link to this article:

Leave a Reply

Your email address will not be published.