Working with the Help Options


Windows PowerShell has a high level of discoverability; that is, to learn how to use PowerShell, you can simply use PowerShell. Online help serves an important role in assisting in this discoverability. The help system in Windows PowerShell can be entered by several methods. To learn about using Windows PowerShell, use the Get-Help cmdlet as follows:

 get-help get-help

This command prints out help about the Get-Help cmdlet. The output from this cmdlet is illustrated here:

 NAME     Get-Help SYNOPSIS     Displays information about Windows PowerShell cmdlets and concepts SYNTAX     Get-Help [[-name] <string>] [-component <string[]>] [-functionality <string     []>] [-role <string[]>] [-category <string[]>] [-full] [<CommonParameters>]     Get-Help [[-name] <string>] [-component <string[]>] [-functionality <string     []>] [-role <string[]>] [-category <string[]>] [-detailed] [<CommonParamete     rs>]     Get-Help [[-name] <string>] [-component <string[]>] [-functionality <string     []>] [-role <string[]>] [-category <string[]>] [-examples] [<CommonParamete     rs>]     Get-Help [[-name] <string>] [-component <string[]>] [-functionality <string     []>] [-role <string[]>] [-category <string[]>] [-parameter <string>] [<Comm     onParameters>] DETAILED DESCRIPTION     The Get-Help cmdlet displays information about Windows PowerShell cmdlets a     nd concepts. You can also use "Help {<cmdlet name> | <topic-name>" or "<cmd     let-name> /?". "Help" displays the help topics one page at a time. The "/?"      displays help for cmdlets on a single page. RELATED LINKS     Get-Command     Get-PSDrive     Get-Member REMARKS     For more information, type: "get-help Get-Help -detailed".     For technical information, type: "get-help Get-Help -full".

The good thing about online help with the Windows PowerShell is that it not only displays help about commands, which you would expect, but also has three levels of display: normal, detailed, and full. Additionally, you can obtain help about concepts in Windows PowerShell.

This last feature is equivalent to having an online instruction manual. To retrieve a listing of all the conceptual help articles, use the Get-Help about* command as follows:

 get-help about*

Suppose you do not remember the exact name of the cmdlet you wish to use, but you remember it was a get cmdlet? You can use a wild card, such as an asterisk (*), to obtain the name of the cmdlet. This is shown here:

 get-help get*

This technique of using a wild card operator can be extended further. If you remember that the cmdlet was a get cmdlet, and that it started with the letter p, you can use the following syntax to retrieve the desired cmdlet:

 get-help get-p*

Suppose, however, that you know the exact name of the cmdlet, but you cannot exactly remember the syntax. For this scenario, you can use the -examples argument. For example, for the Get-PSDrive cmdlet, you would use Get-Help with the -examples argument, as follows:

 get-help get-psdrive -examples

To see help displayed one page at a time, you can use the help function, which displays the help output text through the more function. This is useful if you want to avoid scrolling up and down to see the help output. This formatted output is shown in Figure 1-2.

image from book
Figure 1-2: Using help to display information one page at a time

Getting tired of typing Get-Help all the time? After all, it is eight characters long, and one of them is a dash. The solution is to create an alias to the Get-Help cmdlet. The commands used for this are in the CreateAliasToGet-Help.txt file. An alias is a shortcut key stroke combination that will launch a program or cmdlet when typed. In the creating an alias for the Get-Help cmdlet procedure, we will assign the Get-Help cmdlet to the gh key combination.

Note 

To create an alias for a cmdlet, confirm there is not already an alias to the cmdlet by using Get-Alias. Use Set-Alias to assign the cmdlet to a unique key stroke combination.

Creating an alias for the Get-Help cmdlet

  1. Start Windows PowerShell by using Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents And Settings.

  2. Retrieve an alphabetic listing of all currently defined aliases, and inspect the list for one assigned to either the Get-Help cmdlet or the key stroke combination gh. The command to do this is as follows:

     get-alias |sort

  3. After you have determined that there is no alias for the Get-Help cmdlet, and that none is assigned to the gh key stroke combination, review the syntax for the Set-Alias cmdlet. Use the -full argument to the Get-Help cmdlet. This is shown here:

     get-help set-alias -full

  4. Use the Set-Alias cmdlet to assign the gh key stroke combination to the Get-Help cmdlet. To do this, use the following command:

     set-alias gh get-help




Microsoft Press - Microsoft Windows PowerShell Step by Step
MicrosoftВ® Windows PowerShell(TM) Step By Step (Step By Step (Microsoft))
ISBN: 0735623953
EAN: 2147483647
Year: 2007
Pages: 128
Authors: Ed Wilson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net