PowerShell is an effective command line interface to retrieve information about computer systems and services. Type in a command like get-service, and you receive a listing of all the services on a Windows system and their status.
PS C:\GitHub\demos>get-serviceStatus Name DisplayName
------ ---- -----------
Running AdobeARMservice Adobe Acrobat Update Service
Stopped AJRouter AllJoyn Router Service
Stopped ALG Application Layer Gateway Service
Stopped AppIDSvc Application Identity
Running Appinfo Application Information
Stopped AppMgmt Application Management
Stopped AppReadiness App Readiness
Stopped AppVClient Microsoft App-V Client
Stopped AppXSvc AppX Deployment Service (AppXSVC)Stopped AssignedAccessM... AssignedAccessManager Service
Running AudioEndpointBu... Windows Audio Endpoint Builder
Running Audiosrv Windows Audio
While helpful, you might think there must be more information on the services running on a system than what is displayed here. Well, there is. By default, PowerShell uses default views to display common properties when commands are run. To see all of the properties available from a command, we use the pipeline, and a command called Get-Member. One of the commands everyone should know, Get-Member retrieves the 'membership' of an object by showing its properties and methods. This is accomplished by using a command's output as input for get-member, like the syntax below.
Some-Command | Get-Member or gm (analiasforget-member)
Now let's see what information lies within the output of get-service.
So now that you know the properties available for each get-service object, you use the data contained in each property anyway you see fit. For ease of demonstration, lets say you have a server whose services are not starting up properly, and you believe the issue may be due to dependent services not starting in a timely fashion. To assist, you want a list of all services including service name, service status, and the names of any services depended on (ServicesDependedOn) to start properly. Using format-table, we can view that in a flash.
And there you have your table showing all the information you need.
Another great use for get-member is when working with Active Directory objects. As you can imagine, user objects have a bunch of properties, and they are not all displayed when using the Get-ADUser command. Using Get-Member will help you find all the properties for user objects.
Important Note With Get-ADUser and other Get- commands for Active Directory, the default usage only displays a subset of the properties available on a user object. To retrieve all the properties associated with an AD object, you need to add the parameter -Properties with the '*' (or wildcard) value. Here's how to use Get-Member to see all the user properties.
Get-ADUser -Properties * | Get-Member
So next time you run into a PowerShell command and it is not giving you all the information you need, turn to Get-Member.
For more information on Get-Member, check out the docs here
For more information on Get-ADUser, check out the docs here