MCPMag.com

Sign up for our newsletter.

I agree to this site's Privacy Policy.

Prof. Powershell

PowerShell Screen Buffer Size: Sometimes More Is Better

Here's how to handle command lines that are a lot longer than your display is set for.

If you are new to PowerShell, chances are you are new to the command line world as well. One thing you have probably run into is that some commands return a lot of information, often scrolling right off the screen. Let me give you some tips on how to handle this.

The first thing I always do is increase the screen buffer. On an open PowerShell session, right-click the upper left corner and select Properties. Select the Layout tab. Change the height of the screen buffer size as I've done in Figure 1 and click OK.

Invoke-WebRequest cmdlet

Figure 1. (Click image to view larger version.)

I generally set it to something over 1000, but you can experiment with a value that works for you. This value controls how far you can scroll vertically after a command has finished running. The larger the number, the further you can scroll before data is overwritten.

The next step you can take is to use the More command. This is a legacy command line tool that in essence "pages" the output once screen at a time. The usual technique is to run your command and pipe it to More.

PS Scripts:\> get-process | moreg

At the end of each page is a break.

… 398 19 4796 11920 107 1.59 1628 OpenDNSUpdater 143 8 3196 10980 46 2.93 4896 OSPPSVC 767 73 176020 197744 820 29.23 4192 powershell -- More --

Pressing the Space bar will advance to the next page. Pressing Enter will advance one line of data at a time. Or you can use one of these options.

  • P You will be prompted for the next X number of lines to advance
  • S Skip the next X number of lines
  • F Display the next "file" or page of data
  • Q Quit

More was originally intended as a way to page through large text files. And you can still use it that way. Both of these commands will have the same effect.

PS Scripts:\> more C:\windows\WindowsUpdate.log
PS Scripts:\> get-content C:\windows\WindowsUpdate.log | more

In PowerShell, the More command is actually a function that wraps around more.com. The "real" command has a few more features you can take advantage of as long as you pipe your expression to More.com.

PS Scripts:\> get-wmiobject win32_computersystem | select * | more.com

You might want to use these options:

  • C Clear the screen
  • +N Start at line N
  • S Try to merge blank lines into one

PS Scripts:\> more.com /c /S +10 c:\work\demo.txt

This will attempt to start at line 10 of demo.txt after clearning the screen and attempting to squeeze blank lines together. If you want to learn more, ask for command help:

PS C:\> more.com /?

So the next time you feel overwhelmed with data, take it a little bit at a time with More.

 

About the Author

Jeffery Hicks is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with over 20 years of experience, much of it spent as an IT consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant. Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular contributor to the Petri IT Knowledgebase and 4SysOps. If he isn't writing, then he's most likely recording training videos for companies like TrainSignal or hanging out in the forums at PowerShell.org. Jeff's latest books are Learn PowerShell 3 in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches and PowerShell in Depth: An Administrators Guide. You can keep up with Jeff at his blog http://jdhitsolutions.com/blog, on Twitter at twitter.com/jeffhicks and on Google Plus (http:/gplus.to/JeffHicks)

comments powered by Disqus

Reader Comments:

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above