I'm a PowerShell 5, but I use CTRL+R so +2.
We have a different kind of an article today. Instead of talking about PowerShell commands or PowerShell scripting, we'll look at interacting with the Windows PowerShell shell itself, and how you can use keyboard shortcuts to speed up our work.
Clear Screen: CTRL+L
I need to establish a clean screen before I do anything serious in PowerShell. Pressing CTRL+L is faster than running Clear-Host (and it works in Linux shells too!)
Faster Copy Paste
In Windows PowerShell, you can highlight a command with your mouse then press CTRL+C to copy. Paste with CTRL+C. No big revelation there.
But Windows PowerShell also supports automatic command highlighting with CTRL+A. Once it's highlighted, press CTRL+C. No mouse required!
History Recall: CTRL+R
You can press the up arrow to go back through your PowerShell session history, but you can also search quickly. Press CTRL+R and type a few letters that you remember from the previous command, and PowerShell will show you any matches.
Interactive Editing: Shift+Enter
Let's say you copy-paste a PowerShell 1-liner from some GitHub gist page. You can move the cursor using the left and right arrows and add a new line without executing the command by pressing Shift+Enter. Press Ctrl+Enter if you want to add a new line above the current line.
Last Argument Copy: Alt+.
The last argument to a command is something that is often reused. You don't have to type it more than once: press Alt+. (Option + . on macOS) to insert the last argument of the previous command automatically.
Select Completion: Ctrl+Space
We know you can press Tab to complete a command or option, but you can also press Ctrl+Space to get a visual selection of matching commands, choosing the one you want with arrow keys. If help information is available, it will be displayed automatically.
Numeric Arguments: Alt+N
You can press Alt+Number (e.g., Alt+7) then any added character to input that many characters. If you need more than 9 characters, keep holding Alt and press the number of characters you need.
For example, want to enter 62 * characters? Press Alt+62, then press *:
Want to backspace 7 times? Alt+7, then press backspace:
This works for arrow keys and any other repeated input characters as well.
Command Dump: Ctrl+Alt+Shift+?
Finally, get a list of keyboard shortcuts by pressing Ctrl+Alt+Shift+?
Conclusion
Some of these I already use all the time, but others I probably won't use. But they are all useful anytime you feel like you need to +2 your PowerShell game.
-Joshua Wright
Return to Getting Started With PowerShell
Joshua Wright is the author of SANS SEC504: Hacker Tools, Techniques, and Incident Handling, a faculty fellow for the SANS Institute, and a senior technical director at Counter Hack.