One of the most useful cmdlets is Get-Member, which displays information about the .NET Framework object that a command returns. The information includes the type, properties, and methods of the object.
To use Get-Member, use a pipeline operator (|) to send the results of a command to Get-Member. For example:
get-service | get-member
This command reveals that Get-Service actually returns a set of System.ServiceProcess.ServiceController objects -- one for each service on the computer.
TypeName: System.ServiceProcess.ServiceController Name MemberType Definition ---- ---------- ---------- Name AliasProperty Name = ServiceName add_Disposed Method System.Void add_Disposed(EventHandler value) Close Method System.Void Close() Continue Method System.Void Continue() CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType) Dispose Method System.Void Dispose() Equals Method System.Boolean Equals(Object obj) ExecuteCommand Method System.Void ExecuteCommand(Int32 command) get_CanPauseAndContinue Method System.Boolean get_CanPauseAndContinue() get_CanShutdown Method System.Boolean get_CanShutdown() get_CanStop Method System.Boolean get_CanStop() get_Container Method System.ComponentModel.IContainer get_Container() get_DependentServices Method System.ServiceProcess.ServiceController[] get_DependentServices() get_DisplayName Method System.String get_DisplayName() get_MachineName Method System.String get_MachineName() get_ServiceHandle Method System.Runtime.InteropServices.SafeHandle get_ServiceHandle() get_ServiceName Method System.String get_ServiceName() get_ServicesDependedOn Method System.ServiceProcess.ServiceController[] get_ServicesDependedOn() get_ServiceType Method System.ServiceProcess.ServiceType get_ServiceType() get_Site Method System.ComponentModel.ISite get_Site() get_Status Method System.ServiceProcess.ServiceControllerStatus get_Status() GetHashCode Method System.Int32 GetHashCode() GetLifetimeService Method System.Object GetLifetimeService() GetType Method System.Type GetType() InitializeLifetimeService Method System.Object InitializeLifetimeService() Pause Method System.Void Pause() Refresh Method System.Void Refresh() remove_Disposed Method System.Void remove_Disposed(EventHandler value) set_DisplayName Method System.Void set_DisplayName(String value) set_MachineName Method System.Void set_MachineName(String value) set_ServiceName Method System.Void set_ServiceName(String value) set_Site Method System.Void set_Site(ISite value) Start Method System.Void Start(), System.Void Start(String[] args) Stop Method System.Void Stop() ToString Method System.String ToString() WaitForStatus Method System.Void WaitForStatus(ServiceControllerStatus desiredStatus), System.Voi... CanPauseAndContinue Property System.Boolean CanPauseAndContinue {get;} CanShutdown Property System.Boolean CanShutdown {get;} CanStop Property System.Boolean CanStop {get;} Container Property System.ComponentModel.IContainer Container {get;} DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;} DisplayName Property System.String DisplayName {get;set;} MachineName Property System.String MachineName {get;set;} ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;} ServiceName Property System.String ServiceName {get;set;} ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;} ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;} Site Property System.ComponentModel.ISite Site {get;set;} Status Property System.ServiceProcess.ServiceControllerStatus Status {get;}
This information looks very technical, but it is actually very practical.
-
The typename (such as "System.ServiceProcess.ServiceController") tells you what type of .NET object the cmdlet returns. For information about objects in this .NET class, paste the typename in the Search text box in MSDN. The associated MSDN topic includes information about the properties and methods of objects in this class, including the objects that Get-Service returns.
-
The Property types represent properties of the objects. The value of each property is information about the service object. For example, the ServiceController objects have a CanPauseAndContinue property. The MSDN description of the property explains that the property tells whether the service can be paused and resumed.
To list the value of a property of a particular service, type:
such as:(get-service <service-name>).<property-name>
To display a list with the name and the value of the CanPauseAndContinue property of the Alerter service, type:(get-service alerter).canpauseandcontinue
To display a list of the values of all properties of the Alerter service, type:get-service alerter | format-list -property name, CanPauseAndContinue
To display a table with the name and the value of the CanPauseAndContinue property of all services, type:get-service alerter | format-list -property *
get-service | format-table -property name, CanPauseAndContinue
-
The Method types represent methods of the object, that is, actions that you can perform on the object. For example, ServiceController objects have a Stop method that lets you stop the service.
To call a method of a service object, use the following format. (Be sure to include the parentheses).
(get-service <service-name>).<method-name>() For example, (get-service schedule).stop()
For more information about the Get-Member command, type:
get-help get-member -detailed