Tabbing Through PowerShell Commands
One of the benefits of knowing the verbs is that it
enables you to easily discover the commands using the tab completion,
or tab expansion feature. With more than 400 commands, you simply can’t
remember them all. However, you can remember common verbs such as get, set, start, and stop.
You enter the name of the verb, and then simply press the Tab key to
discover all the available commands. The following steps show this
process.
Step | Comments |
---|
1. Launch PowerShell. | Click Start, type PowerShell in the Search text box, and double-click Windows PowerShell. |
2. Type get-. | get is a common noun. It retrieves information. |
3. Press the Tab key. | The get command changes to Get-Acl. If you press Enter at this point, it executes the get-acl command.
Note
PowerShell is not case sensitive, but it does automatically change to
Pascal casing, or camel case, for easier readability. Camel casing uses
an uppercase letter for each new word.
|
4. Continue to press the Tab key to discover all of the commands beginning with get-. | There are about 50 get commands that you can discover using this method.
Note
The command get-command get* | measure-object shows the exact number of commands.
|
5. Press the Esc key to clear the PowerShell command. | Pressing Esc clears the command line the same way in PowerShell as it works from the command prompt. |
6. Type set-. | set is another common noun. It is used to configure settings. |
7. Press the Tab key. | The set command changes to Set-Acl. If you press Enter at this point, it tries to execute the set-acl command. However, because the set-acl command requires additional parameters, it won’t complete.
Tip
You can get additional help on any command by entering the get-help command. For example, get-help set-acl retrieves information on this command.
|
8. Continue to press the Tab key to discover all of the commands beginning with set-. | There are about 35 set commands that you can discover using this method.
Note
The command get-command set* | measure-object shows the actual count based on the version of PowerShell you’re running.
|
9. Try the same method with any of the other verbs, such as out or write. | This is one of the core self-discovery methods built into Windows PowerShell. |
Tip
Windows PowerShell has the equivalent of
the command prompt’s doskey. It keeps a history of previous commands,
and you can use the up arrow, down arrow, F7, home, end, page up, and
page down keys to navigate through the history. The get-command *history* command shows all the commands you can use with history. For example, you can execute get-history to show a listing of all commands you’ve entered during this session.
Understanding the Different Types of PowerShell Commands
All PowerShell commands aren’t the same. There are actually three distinct types of commands, as shown in the following table.
Type | Comments |
---|
Cmdlet | Cmdlets
are mini-programs. They are created as objects with properties and
methods. Properties describe the object and methods perform actions. |
Alias | Aliases are simpler names for common commands. For example, you can enter the command get-alias to list all aliases. The get-alias command actually has two aliases that you can execute instead of get-alias: gal and alias. All three commands (get-alias, gal, and alias) perform the same command. |
Function | Functions perform a specific action. For example, the E: function changes the drive to E. The clear-host function clears the screen. |
Note
You can create your own cmdlets, aliases,
and functions. Creating cmdlets can be complex, but creating aliases
and functions is easy.