< Back
Write-ColorText
Post
NAME Write-ColorText
SYNOPSIS
Writes text to the console using tags in the string itself
to indicate the output color of the text. Can replace
Write-Host cmdlet.
SYNTAX
Write-ColorText [-String] <String> [-ForegroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed |
DarkMagenta | DarkYellow | Gray | DarkGray | Blue | Green | Cyan | Red | Magenta | Yellow | White}]
[-BackgroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed | DarkMagenta | DarkYellow | Gray | DarkGray
| Blue | Green | Cyan | Red | Magenta | Yellow | White}] [-NoNewline] [-NoColor] [<CommonParameters>]
DESCRIPTION
This script allows you to use custom markup to more easily
write multi-colored text to the console. Can replace
Write-Host cmdlet.
It uses the general format of:
!(foreground,background)
to define a color setting.
both background and foreground can be omitted, but the comma
is required if you specify a background color.
The following are all valid:
!(red)
!(,red)
!(blue,)
!(yellow,black)
If you don't specify a color it will continue using the current
color. If you specify "*" as a color it will revert to the default
color.
You can escape the markup using an additional '!':
!!(red)
PARAMETERS
-String <String>
The string to write out.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-ForegroundColor
Initial Foreground color.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-BackgroundColor
Initial Background color.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NoNewline [<SwitchParameter>]
Do not append a newline after writing out text.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-NoColor [<SwitchParameter>]
Disable color output.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
OUTPUTS
None
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-ColorText "This is a test !(gray)[ !(red)fail!(gray) ]"
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Write-ColorText "This is a test !(gray)[!(black,green) fail !(gray,*)]"
RELATED LINKS
SYNOPSIS
Writes text to the console using tags in the string itself
to indicate the output color of the text. Can replace
Write-Host cmdlet.
SYNTAX
Write-ColorText [-String] <String> [-ForegroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed |
DarkMagenta | DarkYellow | Gray | DarkGray | Blue | Green | Cyan | Red | Magenta | Yellow | White}]
[-BackgroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed | DarkMagenta | DarkYellow | Gray | DarkGray
| Blue | Green | Cyan | Red | Magenta | Yellow | White}] [-NoNewline] [-NoColor] [<CommonParameters>]
DESCRIPTION
This script allows you to use custom markup to more easily
write multi-colored text to the console. Can replace
Write-Host cmdlet.
It uses the general format of:
!(foreground,background)
to define a color setting.
both background and foreground can be omitted, but the comma
is required if you specify a background color.
The following are all valid:
!(red)
!(,red)
!(blue,)
!(yellow,black)
If you don't specify a color it will continue using the current
color. If you specify "*" as a color it will revert to the default
color.
You can escape the markup using an additional '!':
!!(red)
PARAMETERS
-String <String>
The string to write out.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-ForegroundColor
Initial Foreground color.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-BackgroundColor
Initial Background color.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NoNewline [<SwitchParameter>]
Do not append a newline after writing out text.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-NoColor [<SwitchParameter>]
Disable color output.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
OUTPUTS
None
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-ColorText "This is a test !(gray)[ !(red)fail!(gray) ]"
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Write-ColorText "This is a test !(gray)[!(black,green) fail !(gray,*)]"
RELATED LINKS