December 12, 2018

Get-Command -Syntax vs Get-Help

Wait, is Get-Help or Get-Command right? At the PowerShell Summit 2015 I witnessed Lee Holmes state that Get-Command is always the better way to look up the syntax of a cmdlet. What did he mean by that? Get-Help and Get-Command are two of the only three cmdlets you need to know. The other being Get-Member. Why do you need both Get-Command AND Get-Help?

A quick glance at the output of both commands reveals that the syntax parameter for Get-Command is similar to the help provided by Get-Help. Their function is very similar but derive their information from slightly different sources. When they show conflicting information, which one is correct?

Get-Help Limitations

To understand the limitations of Get-Help, you need to know where Get-Help gets it’s content from. Get-Help shows the MAML or Comment-Based help written by the module author. It may also show generic help populated by PowerShell at run time. PowerShell will attempt to give you something when you ask for help on a cmdlet that doesn’t provide any.

The help built into PowerShell also needs to be updated before you can rely on it. The installed help has to correspond to the version you’re running.

Get-Command Syntax

Get-Command with the Syntax parameter ignores whatever the module author wrote for help and looks directly at the code on your machine to build out what parameters the cmdlet supports.

The distinction is important when the help, or documentation of code is out of date. Another example would be if you used Update-Help and pulled down help for a newer version of the help than what you are running locally. Maybe a parameter was renamed, removed, or added in the help to reflect new functionality that you simply don’t have yet.

Source of Truth

The truth is, Get-Command -Syntax should be considered the source of truth when you are sitting at the console. It works out of the box, there isn’t a need to download anything for it to function, and it doesn’t rely on the module author to provide accurate documentation.