Prof. Powershell

Can I Get a Little Help Here?

The Get-Help cmdlet has some useful features you might want to take advantage of.

If you've been paying attention in Prof. PowerShell's class you should know by now how to get help for new cmdlets by using the help command:

PS C:\> help get-service -full

What you may not have realized is that help is a function that wraps around the Get-Help cmdlet, primarily to make it easier to use. However, the actual Get-Help cmdlet has some useful features you might want to take advantage of.
For example, many times all you need is just the syntax for a given cmdlet. The Get-Help cmdlet writes a help object to the pipeline and one of its properties is syntax. Thus you can use a Windows PowerShell one-liner like this:

PS C:\> (get-help new-item).syntax

Personally, I usually need help remembering how to use a particular parameter or if it can accept pipelined input. I don't really want to wade through the full cmdlet help. An expression like this is much, much easier:

PS C:\> Get-Help Get-WmiObject -Parameter Computername

Or perhaps you'd like to know what all the cmdlets you have in your PowerShell session can do. This one-liner will give you a sorted report:

PS C:\> get-help -Category cmdlet | Where {$_.category -match "cmdlet"} | sort Name | format-table Name,Synopsis -wrap -autosize

You may be wondering about the filtering for cmdlet again when I'm already specifying the category. Turns out that the cmdlet category in Get-Help also returns aliases. Since I don't want the duplication I've filtered them out. Here's one more, albeit advanced, example:

PS C:\> get-help * -Category Cmdlet | Where {$_.category -match "cmdlet"} | Sort Name | Select Name, Synopsis, @{Name="Online";Expression={($_.relatedlinks.navigationlink | where {$_.uri -match "http"}).uri}} | ConvertTo-HTML –title "Cmdlet Info"| out-file c:\work\cmdletinfo.htm

There is some useful information tucked away in the help object such as the related links. Because PowerShell 2.0 has online help, I've put together an expression that gets all cmdlets, their synopses and a custom property called Online which contains the URL. All of this is saved to an HTML file. For extra credit brownie points I'll leave it to you to expand this example so that the HTML file has clickable links.

To learn more take a look at full help for the Get-Help cmdlet.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

Upcoming Training Events