Can I Get a Little Help Here? The Get-Help Cmdlet
It happens to all of us: We forget things. Use the PowerShell Get-Help cmdlet to rejog your memory.
I've spent a number of columns recently on more advanced topics. But some of you may just be joining the class so I'm going to revisit some basic PowerShell concepts over the next few weeks. Even if you think you know the material I hope you'll take a few minutes because I may point out something you didn't realize existed. Even after all these years I still discover new nuggets of PowerShell goodness.
I think that PowerShell's help system is one of its greatest strengths. Everything is well documented and right at your fingertips. You can use the Get-Help cmdlet, or a built-in function, Help, on practically any topic or command. You can even use wildcards. Try this command:
PS C:\> help *WMI*
You get a number of items, any of which you can get help on:
PS C:\> help Register-WmiEvent
The initial help displayed is not everything. Remember you can use the -Full parameter:
PS C:\> help Register-WmiEvent -full
By the way, if you only want to see the examples use the -Examples parameter:
PS C:\> help Register-WmiEvent -examples
The full help can sometimes be overwhelming. There are some situations when all you want to see is help on a specific parameter. For example, the Register-WmiEvent cmdlet has a -Action parameter. But how do I use it? The Get-Help cmdlet, as well as the Help function, have a parameter called -Parameter. To retrieve help on the Action parameter, run this:
PS C:\> help Register-WmiEvent -Parameter Action
This should tell you everything you need to know. You can also use wildcards:
PS C:\> get-help Register-WmiEvent -Parameter *
When you use Get-Help, the output is an object which means you can get a little more granular. This won't work using the Help function. Pipe a parameter to Get-Member to see for yourself:
PS C:\> get-help Register-WmiEvent -Parameter action | get-member
This means I can run an expression like this:
PS C:\> get-help Register-WmiEvent -Parameter action | Select Name,Required,PipelineInput
Or extend this to all parameters and dive deep into the cmdlet:
PS C:\> get-help Register-WmiEvent -Parameter * | Sort Required | Select Name,Required,PipelineInput,ParameterValue
If you feel totally self-referential or introspective you should check out the help parameter itself:
PS C:\> help get-help -Parameter parameter
So don't stumble around aimlessly or be embarrassed to ask for directions. Get help and reach your destination.
Jeffery Hicks is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with over 20 years of experience, much of it spent as an IT consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant. Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular contributor to the Petri IT Knowledgebase and 4SysOps. If he isn't writing, then he's most likely recording training videos for companies like TrainSignal or hanging out in the forums at PowerShell.org.
Jeff's latest books are Learn PowerShell 3 in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches and PowerShell in Depth: An Administrators Guide.
You can keep up with Jeff at his blog http://jdhitsolutions.com/blog, on Twitter at twitter.com/jeffhicks and on Google Plus (http:/gplus.to/JeffHicks)