Get-Service - Cmdlet Syntax and Real World Examples

April 06, 2018 0 Comments PowerShell, Get-Service

SYNOPSIS

Gets the services on a local or remote computer.

ALIAS

GSV

DESCRIPTION

The Get-Service cmdlet gets objects that represent the services on a local computer or on a remote computer, including running and stopped services.

You can direct this cmdlet to get only particular services by specifying the service name or display name of the services, or you can pipe service objects to this cmdlet

SYNTAX

Get-Service [-ComputerName <String[]>] [-DependentServices] -DisplayName <String[]> [-Exclude <String[]>] [-Include <String[]>] [-RequiredServices] [<CommonParameters>]

Get-Service [-ComputerName <String[]>] [-DependentServices] [-Exclude <String[]>] [-Include <String[]>] [-InputObject <ServiceController[]>] 
[-RequiredServices] [<CommonParameters>]

Get-Service [[-Name] <String[]>] [-ComputerName <String[]>] [-DependentServices] [-Exclude <String[]>] [-Include <String[]>] [-RequiredServices] [<CommonParameters>]

REAL WORLD EXAMPLES

Get-Service -DisplayName *print* -ComputerName srv01, srv02, srv03, srv04 | select-object machinename, status, name, displayname | sort-object machinename

MachineName  Status  Name    DisplayName
-----------  ------  ----    -----------
srv01        Running Spooler Print Spooler
srv02        Running LPDSVC  TCP/IP Print Server
srv03        Running Spooler Print Spooler
srv04        Running Spooler Print Spooler
  • gets the service status of all services with the word Print in the DisplayName
  • returns the results but only displays the MachineName, Status, Name and DisplayName fields

get-service -DisplayName *spool*

Status   Name               DisplayName
------   ----               -----------
Stopped  Spooler            Print Spooler

  • finds services that contain spool in the displayname
  • Stops the services that found in the first part of the cmdlet

get-service -DisplayName *spool* | restart-Service
  • finds services that contain spool in the displayname
  • There is no output for this cmdlet. If successful, it just returns to the cmd prompt
You've successfully subscribed to Command Line Ninja
Great! Next, complete checkout for full access to Command Line Ninja
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.
Table fo contents