How to get all properties and methods available for the service in PowerShell?


To display all the properties and methods available for the get-service cmdlet you need to pipeline Get-Member (alias gm). MemberType ‘Property’ is to display the specific property like machinename, servicename, etc. and with the MemberType ‘Method’ you can perform specific operations on the object, for example, Start, Stop, Pause the service, etc.

Command

The below command is to display all the members (properties, methods) the Get-Service.

Get-Service | Get-Member

Output

Name                         MemberType
----                         ----------
Name                      AliasProperty
RequiredServices          AliasProperty
Disposed                          Event
Close                            Method
Continue                         Method
CreateObjRef                     Method
Dispose                          Method
Equals                           Method
ExecuteCommand                   Method
GetHashCode                      Method
GetLifetimeService               Method
GetType                          Method
InitializeLifetimeService        Method
Pause                            Method
Refresh                          Method
Start                            Method
Stop                             Method
WaitForStatus                    Method
CanPauseAndContinue            Property
CanShutdown                    Property
CanStop                        Property
Container                      Property
DependentServices              Property
DisplayName                    Property
MachineName                    Property
ServiceHandle                  Property
ServiceName                    Property
ServicesDependedOn             Property
ServiceType                    Property
Site                           Property
StartType                      Property
Status                         Property
ToString                   ScriptMethod

Command

To get the properties only.

Get-Service | Get-Member | where{$_.MemberType -eq "Property"}

Output

Name                MemberType
----                ----------
CanPauseAndContinue   Property
CanShutdown           Property
CanStop               Property
Container             Property
DependentServices     Property
DisplayName           Property
MachineName           Property
ServiceHandle         Property
ServiceName           Property
ServicesDependedOn    Property
ServiceType           Property
Site                  Property
StartType             Property
Status                Property

Command

To get the methods only.

Output

Get-Service | Get-Member | where{$_.MemberType -eq "Method"}

Output

Name                      MemberType
----                      ----------
Close                         Method
Continue                      Method
CreateObjRef                  Method
Dispose                       Method
Equals                        Method
ExecuteCommand                Method
GetHashCode                   Method
GetLifetimeService            Method
GetType                       Method
InitializeLifetimeService     Method
Pause                         Method
Refresh                       Method
Start                         Method
Stop                          Method
WaitForStatus                 Method

Updated on: 22-Jan-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements