Windows PowerShell Shortcut Keys

 

 

Like all good command shells, Windows PowerShell includes a number of shortcut keys that can lessen the amount of typing needed to get you through a Windows PowerShell session. (Actually, as far as we know even badcommand shells include shortcuts keys.) This document briefly describes the most commonly-used PowerShell shortcut keys. Because most of these shortcut keys are meaningless without a command history, we’ll assume our PowerShell session has been up and running long enough for us to have issued the following set of commands:

 

cd c:\scripts

get- childitem - recurse

get- executionpolicy

set- executionpolicy Unrestricted

get-process

get-process -name "Notepad"

get-history

cd c:\windows

get- childitem *. dll

clear-host

 

And now let’s take a look at the shortcut keys and what they’re used for.

 

Up Arrow

Moves backward throughthecommand history, beginning with the last command typed and working back towards the first command typed.

 

For example, if the last command you typed was clear-host(as in our sample command history) then pressing the Up arrow key one time will display clear-hostat the command prompt; you can then run this command by pressing ENTER. Pressing the Up arrow key a second time will display the command get- childitem*. dll. Pressing the key a third time displays cd c:\windows, and so on.

 

Down Arrow

Moves forward through the command history. Continuing with the Up arrow example, suppose you backed your way through the command history (starting with the latest command and moving backwards towards the first command) until get-process –name “Notepad”was displayed at the command prompt. If you now press the Down arrow key you’ll move forward through the command history and get-historywill be displayed. Press the Down arrow key a second time and cd c:\windowswill be displayed.

 

PgUp

Displays the first command in the command history.In our example, that causes cd c:\scriptsto be displayed at the command prompt.

 

PgDn

Displays the last command in the command history.In our example, that’s the clear-hostcommand.

 

Left Arrow

Moves the cursor one character to the left on the command line.For example, if the cursor is under the\ in command cd c:\scripts, pressing the Left arrow key will move the cursor under the :.

 

Right Arrow

Moves the cursor one character to the right on the command line.For example, if the cursor is under the :in cd c:\scripts, pressing the Right arrow key will move the cursor under the \.

 

Home

Moves the cursor to the beginning of the command line.

 

End

Moves the cursor to the end of the command line.

 

Control + Left Arrow

Moves the cursor one “word” to the left on the command line.For example, suppose the command line is displaying the command get-process –name “Notepad”; in addition, suppose that the cursor is under any of the characters in the “word” get-process. (In this case, “words” are strings of characters delineated by blank spaces.) Holding down the Ctrl key and pressing the Left arrow key will cause the cursor to move beneath the gin get-process.

 

Control + Right Arrow

Move the cursor one “word” to the right on the command line. For example, suppose the command line is displaying the command get-process –name “Notepad”; in addition, suppose that the cursor is under any of the characters in the “word” –name. (In this case, “words” are strings of characters delineated by blank spaces.) Holding down the Ctrl key and pressing the Right arrow key will cause the cursor to move beneath the in “Notepad”.

 

Control + c

Cancels the current command.If you are partway through typing a command and then press Ctrl+cWindows PowerShell will ignore everything you’ve typed on the line and present you with a new “blank” command line.

 

F2

Creates a new command line from the partial contents of your last command line.For example, suppose your previous command was get-process –name “Notepad”. If you press F2, PowerShell will respond with the following request:

 

 

 

If you type (representing the first quotation mark) PowerShell will insert the text from your previous command, up to (but not including) the double quote mark:

 

get-process –name

 

Note that PowerShell will always go the first instance of a character. If you type an ein the dialog box PowerShell will begin “typing” until it encounters the first ein get-process. Therefore, all that will be displayed on your screen is the following:

 

g

 

To cancel when asked to enter a character, press Enter without entering anything.

 

F3

Displays your previous command.This is equivalent to pressing the Up arrow key once. However, while you can press Uparrow multiple times to continue cycling through your command history, pressing F3 additional times has no effect: only your last command will be displayed.

 

F4

Beginning from the current cursor position, F4 deletes characters up to the specified character. For example, suppose the command get-process –name “Notepad”is displayed, and the cursor is beneath the cin process. If you press F4, the following dialog box appears:

 

 

 

If you press PowerShell will begin deleting characters from the command prompt and continue deleting characters until it encounters a character. In this case, that means the following (nonsensical) command will be displayed:

 

get-pro-name "Notepad"

 

If you enter a character (say, z) which does not appear in the command string then all the remaining characters in the string will be deleted:

 

get-pro

 

This also occurs if you simply press ENTER when the dialog box appears.

 

To cancel this operation, press Ctrl+Z.

 

F5

Like the Up arrow key, F5 moves you backward through the command history.

 

F7

Displays a “dialog box” that allows you to select a command from your command history:

 

 

 

Scroll through the dialog box using the Up and Downarrow keys; when you find a command you want to execute press ENTER. Alternatively, locate the desired command and then press the right arrow key; that will “type” the command at the command prompt but will not execute that command. To then execute the command, you must press ENTER.

 

To dismiss the dialog box without selecting a command, press Escape.

 

F8

Moves backwards through the command history, but only displays commands matching text you type at the command prompt. For example, suppose you type setand then press F8. In that case (and using our sample command history) PowerShell will only display the command set- executionpolicy. Why? Because that’s the only command in the history that matches the string set.

 

Now, type cd and press F8. This time around, PowerShell will display the command cd c:\windows. Press F8 a second time and the command cd c:\scriptswill be displayed. That’s because, in this case, we have two commands that match the string cd .

 

F9

Enables you to run a specific command from the command history.When you press F9 PowerShell prompts you to enter a command number, corresponding to the numbers displayed in the history “dialog box” (see F7):

 

 

To run a command, type the appropriate number and press ENTER. Using our sample history, typing 5 and pressing ENTER runs the command get-process.

 

To cancel this operation, press Escape.