Quantcast
Channel: Powershell – TheITBros
Viewing all articles
Browse latest Browse all 91

Get-service: Checking the Status of Windows Services With PowerShell

$
0
0
get service command

Using the Get-Service cmdlet you can get a list of all the services installed on the operating system, its status and startup type. This one and other cmdlets to get the status and management of Windows services first time appeared in Powershell 1.0. In this article we will demonstrate typical examples of using Get-Service to get the status of a service on local or remote machines, the type of services startup, we’ll cover how to determine the dependencies of services.

You can get a list of services on a local or remote machine by using the Get-Service cmdlet. Get-Service command without parameters returns a list of all services on the local system.

Get-Service

This command will list all local Windows services, their status (running or stopped) and display name.

get service powershell

if you need to display only running services, use this command:

Get-Service | Where-Object {$_.Status -EQ "Running"}

The pipeline operator (|) passes the results to the Where-Object cmdlet, which selects only those services for which the Status parameter is set to “Running”. If you want to display only the stopped services, specify Stopped.

get service where object

You can get all the properties of the service object using the Get-Member.

get-service | get-member

As you can see, these objects have the Typename –  System.ServiceProcess.ServiceController. The screenshot shows all the available properties and methods of service objects in the system (most of them are not used when displaying by default).

get service get member

To display specific properties of the service, use next command. For example, we need to display the name, Display Name, status and features of the Windows Update service:

get-service wuauserv | select Displayname,Status,ServiceName,Can*

DisplayName : Windows Update

Status : Stopped

CanPauseAndContinue : False

CanShutdown : False

CanStop : False

get service get member

For example, to get the type of Windows services startup, run the command (works in PowerShell 5.1):

Get-Service | select -property name,starttype

You can filter the list by the service name using the asterisk as a wildcard:

get-service wi*

You can sort services in descending order by the value of the Status property running services are displayed earlier than stopped:

get-service s* | sort-object status - Descending

To check the existence of a service on the system (usually used in various scripts), execute the following commands:

if (Get-Service "SomeService" -ErrorAction SilentlyContinue)

{

"SomeService exists"

}

You can use the Get-Service cmdlet to get the status of services not only on the local, but also on remote computers. To do this, use the –ComputerName argument. Connection to remote computers is established not through PowerShell Remoting (WinRM), but through Service Manager (similar to the sc.exe command).

get-service wuauserv -ComputerName remotePC1

In PowerShell v3 you can get the status of the service on multiple remote computers at once, their names must be separated by commas.

get-service spooler -ComputerName remotePC1,remotePC2, remotePC3| format-table Name,Status,Machinename –autosize

Use the format-table cmdlet in this example to get a more convenient table with the list of the services status.

The Get-Service cmdlet has two other useful parameters that you can use when managing Windows services. The DependentServices parameter returns services that depend on this service. The RequiredServices parameter returns the services on which this service depends.

The following command receives the services required by the LanmanWorkstation service.

Get-Service -Name LanmanWorkstation –RequiredServices

get service name

The next command returns dependent services that require the LanmanWorkstation service.

Get-Service -Name LanmanWorkstation -DependentServices

The post Get-service: Checking the Status of Windows Services With PowerShell appeared first on TheITBros.


Viewing all articles
Browse latest Browse all 91

Trending Articles