Udostępnij za pośrednictwem


PowerShell Shortcuts

I’m all about shortcuts when it comes to development and there’s no exception for PowerShell.

Browsing around this morning, I found two useful shortcuts that I didn’t know existed.

F7 “History” -  Pressing the F7 key will show a dialog window in PowerShell with a list of commands from your history.  You can also access this list by using the cmdlet  “Get-History”  but I find the dialog WAY more easy than the cmdlet or using the Up arrow key.

F8 “Filtered Commands” -  Pressing the F8 key is much like using the Up arrow key to scroll backwards through your list of commands; however, it allows you to filter the list of commands.  Here’s an example of a list of commands:

1.  cls
2.  Write-Host “Starting my example”
3.  cls
4.  Write-Output “This is fun”
5.  cls
6.  Write-Warning –message “Uh oh, too much fun”
7.  cls
8.  Write-Host “Ending my example”

The way to efficiently use F8, is for command line 6, type only: “write” and then press F8 several times.  It will cycle through all of your previous commands, but only those that started with “write”  (lines 2, 4, and 6). 

Cool: - you will also notice that the cursor is positioned at the end of your filter, so you can easily move it ahead or behind and do a Ctrl + End  to delete the rest of the command line to continue writing.

Comments