Mastering the Three Core Windows PowerShell Cmdlets
- Basic PowerShell Command Structure
- <tt>Get-Command</tt>
- <tt>Get-Help</tt>
- <tt>Get-Member</tt>
- Wrapping Up
If you’re trying to learn Windows PowerShell by memorizing cmdlets, you’re doing it wrong. Just think of all the thousands of PowerShell commands that are built into Microsoft products. Now extrapolate that idea across different vendors and the PowerShell community at large. It’s simply pointless to attempt command memorization on anything but the smallest scale. Instead, the master key to learning Windows PowerShell is a combination of command discovery and usage help. To that end, in this article I describe three core PowerShell cmdlets:
- Get-Command
- Get-Help
- Get-Member
Together these cmdlets give you everything you need to discover and fully understand any PowerShell command you’ll use to do your work. Before we dive in, I strongly suggest that you keep an elevated PowerShell console session open so you can immediately apply what you learn here. Let’s begin!
Basic PowerShell Command Structure
Windows PowerShell commands have the following generic structure:
Verb-prefix_singular_noun
The PowerShell team publishes a list of 90-odd “approved verbs” that PowerShell command authors should use. If you’re wondering what those verbs are, just run the following statement:
Get-Verb | Select-Object -Property Verb | Format-Wide -Column 2
The PowerShell command prefix is a brief identifier (often only two or three characters) that serves the following purposes:
- Avoiding name collisions when different modules are loaded into the same session
- Identifying the command’s parent module
For instance, all the commands in the Active Directory module use the AD prefix, SharePoint Server 2013 commands use SP, and so forth.
The singular-noun part of a PowerShell command makes it easier to guess at the correct command. For example, have you ever asked yourself whether the correct command name is “Get-Service” (singular) or “Get-Services” (plural)? You don’t need to worry anymore, because the best-practice guideline is to make all nouns singular.
Now that we’ve reviewed the anatomy and physiology of a PowerShell command, let’s use Get-Command to discover some commands.