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
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.