This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Out-Host.
When to use Out-Host?
The Out-Host cmdlet sends output to the PowerShell host for display. The host displays the output at the command line. Because Out-Host is the default, you don’t have to specify it unless you want to use its parameters.
Out-Host is automatically appended to every command that is executed. It passes the output of the pipeline to the host executing the command. Out-Host ignores ANSI escape sequences.
The escape sequences are handled by the host. Out-Host passes ANSI escape sequences to the host without trying to interpret or change them.
What version of PowerShell am I using for this blog?
Get the PowerShell Version from your machine:
This command shows you the PowerShell version information on your machine.
How to use Out-Host?
Display output one page at a time:
Get-Process | Out-Host -Paging
Get-Process gets the system processes and sends the objects down the pipeline. Out-Host uses the –Paging parameter to display one page of data at a time.
Use a variable as input:
$io = Get-History
Out-Host -InputObject $io
Get-History gets the PowerShell session’s history, and stores the objects in the $io variable. Out-Host uses the -InputObject parameter to specify the $io variable and displays the history.
Learn last week’s command: Set-StrictMode.
Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.