다음을 통해 공유


Using the Out-Host Cmdlet

Viewing Data One Screen at a Time

The Out-Host cmdlet provides a way to write pipelined data to the console window. Big deal, you say: isn’t pipelined data typically written to the console window by default anyway? Yes. But Out-Host does have at least one intriguing capability missing from the standard output: by adding the -paging parameter you can view data one page (screen) at a time, rather than have it all scroll past in one big blur (and possibly overflow the console window buffer along the way). For example, perhaps you’d like to view the Windows PowerShell event log entries, but you’d like to view those entries one screen at a time. No problem: just call Get-EventLog, pipe the data to Out-Host, and add the -paging parameter. Your command should look like this:

Get-Eventlog PowerShell | Out-Host -paging

Or, if you don’t like typing, shorten -paging to -p:

Get-Eventlog PowerShell | Out-Host -p

Either way, your data will be displayed like this:

Notice that only one screen of data is displayed. That screen will remain in place until you press the spacebar (to move to the next screen), press ENTER (to move to the next line), or press Q to quit.

Tip. Windows PowerShell includes a special function - more - that can also be used to display data one screen at a time:

Get-Eventlog PowerShell | more
Out-Host Aliases
  • oh