Jump to content

How to Customize the Shell in Windows PowerShell

0
  chco's Photo
Posted Aug 27 2010 04:58 AM

The following excerpt from Windows PowerShell Cookbook, Second Edition shows you how to customize the PowerShell console to make it more efficient for copying, pasting, history management, and scrolling.
Run the commands shown in the example below to permanently customize your PowerShell console windows and make many tasks easier.

Example 1-8. Set-ConsoleProperties.ps1

Push-Location
Set-Location HKCU:\Console
New-Item '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'
Set-Location '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'

New-ItemProperty . ColorTable00 -type DWORD -value 0x00562401
New-ItemProperty . ColorTable07 -type DWORD -value 0x00f0edee
New-ItemProperty . FaceName -type STRING -value "Lucida Console"
New-ItemProperty . FontFamily -type DWORD -value 0x00000036
New-ItemProperty . FontSize -type DWORD -value 0x000c0000
New-ItemProperty . FontWeight -type DWORD -value 0x00000190
New-ItemProperty . HistoryNoDup -type DWORD -value 0x00000000
New-ItemProperty . QuickEdit -type DWORD -value 0x00000001
New-ItemProperty . ScreenBufferSize -type DWORD -value 0x0bb80078
New-ItemProperty . WindowSize -type DWORD -value 0x00320078
Pop-Location


These commands customize the console color, font, history storage properties, QuickEdit mode, buffer size, and window size.

With these changes in place, you can also improve your productivity by learning some of the hotkeys for common tasks, listed in Table 1-2. PowerShell uses the same input facilities as cmd.exe, and so it brings with it all the input features that you are already familiar with—and some that you aren’t!

Table 1-2. Partial list of Windows PowerShell hotkeys

HotkeyMeaning
Up arrowScan backward through your command history.
Down arrowScan forward through your command history.
PgUpDisplay the first command in your command history.
PgDownDisplay the last command in your command history.
Left arrowMove cursor one character to the left on your command line.
Right arrowMove cursor one character to the right on your command line.
HomeMove the cursor to the beginning of the command line.
EndMove the cursor to the end of the command line.
Ctrl + Left arrowMove the cursor one word to the left on your command line.
Ctrl + Right arrowMove the cursor one word to the right on your command line.


When you launch PowerShell from the link on your Windows Start menu, it customizes several aspects of the console window:

  • Foreground and background color, to make the console more visually appealing

  • QuickEdit mode, to make copying and pasting with the mouse easier

  • Buffer size, to make PowerShell retain the output of more commands in your console history


By default, these customizations do not apply when you run PowerShell from the Start→Run dialog. The commands given in the solution section improve the experience by applying these changes to all PowerShell windows that you open.

The hotkeys do, however, apply to all PowerShell windows (and any other application that uses Windows’ cooked input mode).

Cover of Windows PowerShell Cookbook
Learn more about this topic from Windows PowerShell Cookbook, 2nd Edition. 

This introduction to the Windows PowerShell language and scripting environment provides more than 430 task-oriented recipes to help you solve the most complex and pressing problems, and includes more than 100 tried-and-tested scripts that intermediate to advanced system administrators can copy and use immediately. You'll find hands-on tutorials on fundamentals, common tasks, and administrative jobs that you can apply whether you're on a client or server version of Windows.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies