Welcome to Day 7 of my “A Month of PowerShell” series. This series will use the series landing page on this blog at //blog.waynesheffield.com/wayne/a-month-of-powershell/. Please refer to this page to see all of the posts in this series, and to quickly go to them.

Sending messages to the user

PowerShell provides several different cmdlets to allow the PowerShell script to send informational messages to the user. This table shows several of them:

Cmdlet Description
Write-Debug Writes a debug message to the console. Uses $DebugPreference variable or -debug parameter
Write-Error Writes an error to the error stream.
Write-EventLog Writes an event to the event log. Requires PowerShell run as administrator
Write-Host Writes output to a host.
Write-Output Sends specified objects to next command in pipeline, or console if last command.
Write-Progress Displays a progress bar – does not display if $ProgressPreference = SilentlyContinue
Write-Verbose Writes text to the verbose message string. Uses $VerbosePreference or -Verbose on any command.
Write-Warning Writes a warning message.

There are many optional parameters for these, so don’t forget to read the help for the cmdlets. A quick example of several of these:

Getting Input from the user

The Read-Host cmdlet allows the script to prompt the user for input, and it waits until text has been entered.

Sending output to other locations

PowerShell provides several cmdlets to pipe output to other locations as well, as the following table shows:

Cmdlet Description
Out-Null Deletes output instead of sending it down the pipeline
Out-Host Sends output to the command line
Out-File Sends output to a file
Out-Printer Sends output to a printer
Out-String Sends objects to the host as string.
Out-Default Sends output to the default formatter and to the default output cmdlet.
Out-GridView Sends output to an interactive table in a separate window

The following script will send all of the processes to the appropriate output: