Export (0) Print
Expand All

Write-Host

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Write-Host

Writes customized output to a host.

Syntax

Parameter Set: Default
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.


Aliases

none

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.


Aliases

none

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-NoNewline

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


Aliases

none

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Object<Object>

Objects to display in the console.


Aliases

none

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.


Aliases

none

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Object

    You can pipe objects to be written to the host.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • 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.


Examples

-------------------------- EXAMPLE 1 --------------------------

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


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

-------------------------- EXAMPLE 2 --------------------------

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


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

-------------------------- EXAMPLE 3 --------------------------

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.


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

-------------------------- EXAMPLE 4 --------------------------

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.


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

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft