Accessing PowerShell
After logging in to your
Windows interactive session, there are several methods to access and use
PowerShell. The first method is from the Start menu, as shown in the
following steps:
1. | Click
Start, All Programs, Accessories, Windows PowerShell.
|
2. | Choose either Windows PowerShell (x86) or Windows
PowerShell.
|
To use the second method,
follow these steps:
1. | Click
Start.
|
2. | Type PowerShell
in the Search Programs and Files text box and press Enter.
|
Both these methods open
the PowerShell console, whereas the third method launches PowerShell
from a cmd command prompt:
1. | Click
Start, Run.
|
2. | Type cmd
and click OK to open a cmd command prompt.
|
3. | At the command prompt, type powershell and
press Enter.
|
Command-Line Interface
(CLI)
The syntax for using
PowerShell from the CLI is similar to the syntax for other CLI shells.
The fundamental component of a PowerShell command is, of course, the
name of the command to be executed. In addition, the command can be made
more specific by using parameters and arguments for parameters.
Therefore, a PowerShell command can have the following formats:
[command name]
[command
name] -[parameter]
[command name]
-[parameter] -[parameter] [argument1]
[command
name] -[parameter] -[parameter] [argument1],[argument2]
When using PowerShell, a
parameter is a variable that can be accepted by a command, script, or
function. An argument is a value assigned to a parameter. Although these
terms are often used interchangeably, remembering these definitions is
helpful when discussing their use in PowerShell.
Navigating the CLI
As
with all CLI-based shells, an understanding is needed in how to
effectively navigate and use the PowerShell CLI. Table 1 lists the editing operations associated with various
keys when using the PowerShell console.
Table 1. PowerShell Console Editing Features
Keys | Editing Operation |
---|
Left and right arrows | Move
the cursor left and right through the current command line. |
Up and down arrows | Moves
up and down through the list of recently typed commands. |
PgUp | Displays
the first command in the command history. |
PgDn | Displays
the last command in the command history. |
Home | Moves
the cursor to the beginning of the command line. |
End | Moves
the cursor to the end of the command line. |
Insert | Switches
between insert and overstrike text-entry modes. |
Delete | Deletes the character at
the current cursor position. |
Backspace | Deletes the character immediately preceding
the current cursor position. |
F3 | Displays the previous command. |
F4 | Deletes
up to the specified number of characters from the current cursor. |
F5 | Moves backward through
the command history. |
F7 | Displays a list of recently typed commands in a
pop-up window in the command shell. Use the up and down arrows to select
a previously typed command, and then press Enter to execute the
selected command. |
F8 | Moves backward through the command history with
commands that match the text that has been entered at the command
prompt. |
F9 | Prompts
for a command number and executes the specified command from the
command history (command numbers refer to the F7 command list). |
Tab | Auto-completes
command-line sequences. Use the Shift+Tab sequence to move backward
through a list of potential matches. |
Luckily, most of the features
in Table 1 are native to the cmd command prompt, which makes
PowerShell adoption easier for administrators already familiar with the
Windows command line. The only major difference is that the Tab key
auto-completion is enhanced in PowerShell beyond what’s available with
the cmd command prompt.
As with the cmd command
prompt, PowerShell performs auto-completion for file and directory
names. So, if you enter a partial file or directory name and press Tab,
PowerShell returns the first matching file or directory name in the
current directory. Pressing Tab again returns a second possible match
and enables you to cycle through the list of results. Like the cmd
command prompt, PowerShell’s Tab key auto-completion can also
auto-complete with wildcards. The difference between Tab key
auto-completion in cmd and PowerShell is that PowerShell can
auto-complete commands. For example, you can enter a partial command
name and press the Tab key, and PowerShell steps through a list of
possible command matches.
PowerShell can also
auto-complete parameter names associated with a particular command.
Simply enter a command and partial parameter name and press the Tab key,
and PowerShell cycles through the parameters for the command that has
been specified. This method also works for variables associated with a
command. In addition, PowerShell performs auto-completion for methods
and properties of variables and objects.