CmdID

CmdID / PowerShell / Cmdlets / Write

Write-Host

Writes customized output to a host. PowerShell reference

From the PowerShell reference 5 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Writes customized output to a host. The Write-Host cmdlet's primary purpose is to produce for-(host)-display-only output, such as printing colored text like when prompting the user for input in conjunction with Read-Host. Write-Host uses the ToString() method to write the output. By contrast, to output data to the pipeline, use Write-Output or implicit 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 PowerShell. NOTE: Starting in Windows PowerShell 5.0, Write-Host is a wrapper for Write-Information. This allows you to use Write-Host to emit output to the information stream. This enables the capture or suppression of data written using Write-Host while preserving backwards compatibility. The $InformationPreference preference variable and InformationAction common parameter do not affect Write-Host messages. The exception to this rule is -InformationAction Ignore, which effectively suppresses Write-Host output. (see "Example 5")

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

Write to the console without adding a new line

Write-Host "no newline test " -NoNewline Write-Host "second string"Identify

Write to the console and include a separator

Write-Host (2,4,6,8,10,12) -Separator ", +2= "Identify

Write with different text and background colors

Write-Host (2,4,6,8,10,12) -Separator ", -> " -ForegroundColor DarkGreen -BackgroundColor WhiteIdentify

Write with different text and background colors

Write-Host "Red on white text." -ForegroundColor red -BackgroundColor whiteIdentify

Suppress output from Write-Host

# The following two statements can be used to effectively suppress output from Write-Host Write-Host "I won't print" -InformationAction Ignore Write-Host "I won't print" 6> $nullIdentify

Parameters

5 in the PowerShell reference
-BackgroundColorSpecifies the background color. There is no default. The acceptable values for this parameter are: - Black - DarkBlue - DarkGreen - DarkCyan - DarkRed - DarkMagenta - DarkYellow - Gray - DarkGray - Blue - Green - Cyan - Red - Magenta - Yellow - White
-ForegroundColorSpecifies the text color. There is no default. The acceptable values for this parameter are: - Black - DarkBlue - DarkGreen - DarkCyan - DarkRed - DarkMagenta - DarkYellow - Gray - DarkGray - Blue - Green - Cyan - Red - Magenta - Yellow - White
-NoNewlineThe string representations of the input objects are concatenated to form the output. No spaces or newlines are inserted between the output strings. No newline is added after the last output string.
-ObjectObjects to display in the host.
-SeparatorSpecifies a separator string to insert between objects displayed by the host.