Come and Check our BETA Alpha version of Powershellcenter.net
Send me your comment to Powershell@powershellcenter.com

Synopsis

Writes customized output to a host.

Syntax

Write-Host [[-Object] <Object>] [-BackgroundColor <ConsoleColor>] [-ForegroundColor <ConsoleColor>] [-NoNewline] [-Separator <Object>] [<CommonParameters>]

Detailed Description

The Write-Host cmdlet customizes output. You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter. The Separator parameter lets you specify a string to use to separate displayed objects. The particular result depends on the program that is hosting Windows PowerShell.

Parameters

-BackgroundColor [<ConsoleColor>]

Specifies the background color. There is no default.

Required?   false
Position?   named
Default value?   None
Accept pipeline input?   false
Accept wildcard characters?   false

-ForegroundColor [<ConsoleColor>]

Specifies the text color. There is no default.

Required?   false
Position?   named
Default value?   None
Accept pipeline input?   false
Accept wildcard characters?   false

-NoNewline [<SwitchParameter>]

Specifies that the content displayed in the console does not end with a newline character.

Required?   false
Position?   named
Default value?   None
Accept pipeline input?   false
Accept wildcard characters?   false

-Object [<Object>]

Objects to display in the console.

Required?   false
Position?   1
Default value?   None
Accept pipeline input?   true (ByValue)
Accept wildcard characters?   false

-Separator [<Object>]

String to the output between objects displayed on the console.

Required?   false
Position?   named
Default value?   None
Accept pipeline input?   false
Accept wildcard characters?   false

Input Type

System.Object

You can pipe objects to be written to the host.

Return Type

None

Write-Host sends the objects to the host. It does not return any objects. However, the host might display the objects that Write-Host sends to it.

Notes

Examples

EXAMPLE 1

PS> PS C:\>write-host "no newline test " -nonewline no newline test PS C:\>

This command displays the input to the console, but because of the NoNewline parameter, the output is followed directly by the prompt.

EXAMPLE 2

PS> PS C:\>write-host (2,4,6,8,10,12) -Separator ", +2= " 2, +2= 4, +2= 6, +2= 8, +2= 10, +2= 12

This command displays the even numbers from 2 through 12. The Separator parameter is used to add the string , +2= (comma, space, +, 2, =, space).

EXAMPLE 3

PS> PS C:\>write-host (2,4,6,8,10,12) -Separator ", -> " -foregroundcolor DarkGreen -backgroundcolor white

This command displays the even numbers from 2 through 12. It uses the ForegroundColor parameter to output dark green text and the BackgroundColor parameter to display a white background.

EXAMPLE 4

PS> PS C:\>write-host "Red on white text." -ForegroundColor red -BackgroundColor white Red on white text.

This command displays the string "Red on white text." The text is red, as defined by the ForegroundColor parameter. The background is white, as defined by the BackgroundColor parameter.