get service command

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


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

You may also like:

Add Calendar Permissions in Office 365 via Powersh... This is a tutorial on how to add calendar permissions in Office 365 for your users via Powershell. You can add permissions onto a specific mailbox, or...
How to copy files with BITS using PowerShell If you use local (and global) networks, you might know that files between systems are transferring by using SMB, FTP or HTTP protocols. The problem wi...
Removing Old and Unused Drivers from Driver Store ... Each time you install or update your device driver, Windows OS (since Vista) continues to store the old version of the driver in the system Driver Sto...
How to transfer FSMO Roles From a Failed Domain Co... In case domain controller, which owns FSMO (Flexible Single Master Operation) roles, is fail (virus attack, fatal software problems or catastrophic ha...
Using PsExec to Run Commands Remotely The PsExec is an easy Windows utility to replace the telnet tool. It allows you to run programs and processes on remote systems, using all the feature...
Comments
  1. Posted by VARADHARAJAN

Add Your Comment