Difference between revisions of "The Basics of the Windows PowerShell 1.0 Interactive Shell"

From Techotopia
Jump to: navigation, search
(The Windows PowerShell Command Prompt)
(PowerShell Command Line Editing Keys)
Line 45: Line 45:
  
 
PowerShell provides a number of special key sequences which speed the task of creating and editing commands in the interactive shell, each of which is outlined in the following table:
 
PowerShell provides a number of special key sequences which speed the task of creating and editing commands in the interactive shell, each of which is outlined in the following table:
 +
 +
<table border="1" cellpadding="5" cellspacing="0" id="E3B" style="border-collapse: collapse; border-color:#cccccc; border-style: solid; border-width: 1px; margin-bottom:20px">
 +
<tr bgcolor="#cccccc" style="color:black" valign="top">
 +
<th>
 +
<p>Key Sequence</p>
 +
</th>
 +
<th>
 +
<p>Description</p>
 +
</th>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
<p>Left Arrow</p>
 +
</td>
 +
<td>
 +
Moves the command line cursor one character to the left.
 +
</td>
 +
</tr>
 +
 +
<tr bgcolor="#e9e9e6">
 +
<td>
 +
Right Arrow
 +
</td>
 +
<td>
 +
Moves the command line cursor one character to the right.
 +
</td>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
<p>Ctrl+Left Arrow</p>
 +
</td>
 +
<td>
 +
Moves the command line cursor one word to the left.
 +
</td>
 +
</tr>
 +
 +
<tr bgcolor="#e9e9e6">
 +
<td>
 +
Ctrl+Right Arrow
 +
</td>
 +
<td>
 +
Moves the command line cursor one word to the right.
 +
</td>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
<p>Delete</p>
 +
</td>
 +
<td>
 +
Deletes the character in the command line at the current cursor position.
 +
</td>
 +
</tr>
 +
 +
<tr bgcolor="#e9e9e6">
 +
<td>
 +
Backspace
 +
</td>
 +
<td>
 +
Deletes the character immediately to the right of the current cursor position.
 +
</td>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
Insert
 +
</td>
 +
<td>
 +
Toggles between character insert and overwrite modes.
 +
</td>
 +
</tr>
 +
 +
<tr bgcolor="#e9e9e6">
 +
<td>
 +
Home
 +
</td>
 +
<td>
 +
Relocates the cursor to the beginning of the command line.
 +
</td>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
End
 +
</td>
 +
<td>
 +
Relocates the cursor to the end of the command line.
 +
</td>
 +
</tr>
 +
 +
<tr bgcolor="#e9e9e6">
 +
<td>
 +
Tab
 +
</td>
 +
<td>
 +
Performs command completion operation whereby the shell attempts to guess at the remainder of the command being entered.
 +
</td>
 +
</tr>
 +
 +
<tr>
 +
<td>
 +
F7
 +
</td>
 +
<td>
 +
Displays a new window containing the command history from which previous commands may be selected.
 +
</td>
 +
</tr>
 +
</table>

Revision as of 20:35, 12 November 2008

Windows PowerShell is both a scripting language and an interactive shell. In interactive shell mode, PowerShell provides a command line prompt at which commands may be entered and executed interactively. The purpose of this chapter is to cover the basics of using the PowerShell 1.0 interactive shell.

The Windows PowerShell Command Prompt

The PowerShell interactive prompt may be accessed in two ways. One option is to launch PowerShell from the Start menu by selecting Start -> All Programs -> Windows PowerShell 1.0 -> Windows PowerShell. Alternatively, PowerShell may be launched from the Windows Command Prompt (cmd.exe) window simply by entering the command powershell. Once loaded, PowerShell will display copyright information, followed by the shell prompt:

Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator>

The interactive shell prompt consists of the letter PS to indicate that the user is working within the PowerShell, followed by the current working directory. The prompt is terminated with a '>' character after which the cursor appears awaiting user input. The current working directory indicates that any file system based operations will take place relative to that directory on the file system. Typing the dir or ls command, therefore, will provide a listing of files and sub-directories in the current working directory (C:\Users\Administrator) in this case:

PS C:\Users\Administrator> dir


    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Users\Administrator


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d-r--         11/7/2008   4:26 PM            Contacts
d-r--         11/7/2008   4:26 PM            Desktop
d-r--         11/7/2008   4:26 PM            Documents
d-r--         11/7/2008   4:26 PM            Downloads
d-r--         11/7/2008   4:26 PM            Favorites
d-r--         11/7/2008   4:26 PM            Links
d-r--         11/7/2008   4:26 PM            Music
d-r--         11/7/2008   4:26 PM            Pictures
d-r--         11/7/2008   4:26 PM            Saved Games
d-r--         11/7/2008   4:26 PM            Searches
d-r--         11/7/2008   4:26 PM            Videos

By default, this will be the home directory of the user who invoked PowerShell. The directory may be changed using cd command, for example:

PS C:\Users\Administrator> cd \windows
PS C:\Windows>

PowerShell Command Line Editing Keys

PowerShell provides a number of special key sequences which speed the task of creating and editing commands in the interactive shell, each of which is outlined in the following table:

Key Sequence

Description

Left Arrow

Moves the command line cursor one character to the left.

Right Arrow

Moves the command line cursor one character to the right.

Ctrl+Left Arrow

Moves the command line cursor one word to the left.

Ctrl+Right Arrow

Moves the command line cursor one word to the right.

Delete

Deletes the character in the command line at the current cursor position.

Backspace

Deletes the character immediately to the right of the current cursor position.

Insert

Toggles between character insert and overwrite modes.

Home

Relocates the cursor to the beginning of the command line.

End

Relocates the cursor to the end of the command line.

Tab

Performs command completion operation whereby the shell attempts to guess at the remainder of the command being entered.

F7

Displays a new window containing the command history from which previous commands may be selected.