Holy Trinity of PowerShell

The three most important cmdlets to remember in PowerShell, in fact the old ones you really need to remember are: Get-Command, Get-Help and Get-Member

Get-Command will give you a list of all installed cmdlets in PowerShell as well as their type, version and source. Additionally it has parameters for -verb or -noun so you can get a full list of all “Get-” cmdlets by typing: get-command -verb get or a list of all cmdlets that deal with services by typing: get-command -noun service

Get-Help is used once you know the command you are after, but you want to know more about how it works or what inputs or output to expect. You can provide some handy parameters to the get-help cmdlet such as -full to show the full help with examples, -showwindow to show the full help output in a searchable windows forms interface or -online to show the full detailed help on the technet website.

Get-Member is by far the cmdlet that I use the most, it gives you any methods and properties the current object in the pipeline has as well as specifying the type of the object your dealing with. This includes any properties that may not be visible by just outputting the object to the screen.

A notable gotcha for this is that if your passing get-member an array of strings (or any collection of any objects) it will give you the properties and methods of a string not an array. To determine if you are dealing with an array use the .gettype() .NET method.

Example:
PS C:\> $a = "Hello World"
PS C:\> $b = "hello", "world" 

PS C:\> $a | Get-Member
TypeName: System.String ..

PS C:\> $b | Get-Member
TypeName: System.String ...

PS C:\> $a.GetType() | select name, basetype
Name        BaseType 
String      System.Object

PS C:\> $b.GetType() | select name, basetype
Name        BaseType 
Object[]    System.Array

Leave a Reply