Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

Using Categories to Help Search PowerShell Help

$
0
0

Summary: Learn how to use advanced features in the Windows PowerShell Get-Help cmdlet to quickly find PowerShell Help information.

Microsoft Scripting Guy, Ed Wilson, is here. It seems that my schedule keeps getting fuller. Tonight is the Windows PowerShell User Group in Charlotte. We will be having a script club, so it should be a really cool learning opportunity. If you have never been to a script club meeting, they are a bit different. For example, tonight we will have a scenario, and everyone will have a certain amount of time to solve the scenario. Then each participant will have a chance to explain their script to the group. It is great learning opportunity. Beginners can ask questions, and solicit help from the more experienced club members. You do not have to make a presentation if you do not want to do so. I always learn something due to the many different ways of approaching a specific problem. If you are in the area tonight, stop on by, it will be great fun.

On Monday October 15, 2012, I speak at the Raleigh SQL users group Raleigh SQL Server User Group about using Windows PowerShell to manage SQL Server 2012. It will be a lot of fun. Then Windows PowerShell Saturday #003 happens in Atlanta, Georgia on October 27. I will be making two presentations there. Of course, the Scripting Wife will be accompanying me to all of these October events. It seems the list of where I will be changes on a daily basis, so you can always check the Scripting Community page to see upcoming Windows PowerShell events in your area.

Playing around with Get-Help

The more I play around with the Get-Help cmdlet, the more I like it. I also seem to continue to find new things to explore with this cmdlet.

Note   In Windows PowerShell 3.0 you must first use the Update-Help cmdlet to update the help files. See this collection of blogs that talk about updatable Help in Windows PowerShell 3.0.

When first learning Windows PowerShell, it is important to get good at using the Get-Command cmdlet, the Get-Member cmdlet and the Get-Help cmdlet. Each of these cmdlets are important because they help with the discoverability of Windows PowerShell. In addition, each cmdlet is powerful and has multiple levels of use. Today, I want to talk a bit about using the Get-Help cmdlet.

There is no alias created for the Get-Help cmdlet, but there is a function called Help. You can use the Help function in the same way that you would use the Get-Help cmdlet. The difference is that the Help function contains a built-in More function. It will automatically display information, one page at a time, when the information takes more than a single page to display in the Windows PowerShell console. In the Windows PowerShell ISE, there is no pager; therefore, the More function does not work.

By default, when using the Get-Help cmdlet, most people type Get-Help and a name of a cmdlet, for example, Get-Process. The command to display Help information about the Get-Process cmdlet is shown here.

Get-Help Get-Process

The command and associated output are shown in the image that follows.

Image of command output

There are four levels of detail that are displayed by the Get-Help cmdlet. The levels are Default, Detailed, Full, and Example. The Detailed, Full, and Example levels are accessible via switched parameters. The first, Default, is the default view.

In addition to the four defined levels of Help, additional parameters accept values to aid in searching the Help files for specific information. Some do not work with the core cmdlets, but they could be implemented by Help writers in the future. The three parameters that do not really work right now are Role, Component, and Functionality.

One of the parameters that is pretty cool is Category. Available categories for this parameter are as follows:

Alias

Cmdlet

Provider

General

FAQ

Glossary

HelpFile

ScriptCommand

Function

Filter

ExternalScript

AllDefaultHelp

Workflow

Because of the way that Windows PowerShell 3.0 automatically finds information in modules that are not yet loaded, use of the Get-Help command provides information about items from the various categories even if they are not loaded. For example, the following command returns Help information on my system, because I have a haswmivalue filter in my HSGWMImoduleV6.

help -Category filter

The command and associated information are shown in the image that follows.

Image of command output

Keep in mind, that when using the Category parameter to find Help information that are related to specific categories of commands, you still have access to the Full, Detailed, and Examples switches. Therefore, the following commands also work.

help -Category filter –Examples

help -Category filter –Detailed

help -Category filter –Full

To find where the filter resides, use the Get-Command cmdlet as shown here.

PS C:\> gcm haswmivalue

 

CommandType     Name                                               ModuleName

-----------     ----                                               ----------

Filter          HasWmiValue                                        HSGWMImoduleV6

To search the About Help files, as opposed to the Cmdlet Help files, use the category HelpFile. The following script illustrates a command to search the About Help files for articles related to operators as well as the output associated with the command.

PS C:\> Get-Help -Category helpfile -name *operator*

 

Name                              Category  Module                    Synopsis

----                              --------  ------                    --------

about_Arithmetic_Operators        HelpFile                            Describes t...

about_Assignment_Operators        HelpFile                            Describes h...

about_Comparison_Operators        HelpFile                            Describes t...

about_Logical_Operators           HelpFile                            Describes t...

about_Operators                   HelpFile                            Describes t...

about_Operator_Precedence         HelpFile                            Lists the W...

about_Type_Operators              HelpFile                            Describes t...

Join me tomorrow when I will talk about more cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy


Viewing all articles
Browse latest Browse all 3333

Trending Articles