Skip to content
ConsoleMonster
Cmdlet

Use-ConsoleTarget

Module ConsoleMonster
Inputs
None

Runs a script block with ConsoleMonster output going somewhere else: a file, a text writer, any target, or a string.

Syntax

Use-ConsoleTarget [-Colors <Ansi16|Ansi256|TrueColor>] [-Glyphs <Ascii|Basic|Full>] [-ScriptBlock] <ScriptBlock> [-Width <Int32>] [<CommonParameters>]
#
Parameter set: String
Use-ConsoleTarget [-Append] [-Colors <Ansi16|Ansi256|TrueColor>] [-Glyphs <Ascii|Basic|Full>] -Path <String> [-ScriptBlock] <ScriptBlock> [-Width <Int32>] [<CommonParameters>]
#
Parameter set: Path
Use-ConsoleTarget [-Colors <Ansi16|Ansi256|TrueColor>] [-Glyphs <Ascii|Basic|Full>] [-ScriptBlock] <ScriptBlock> [-Width <Int32>] -Writer <TextWriter> [<CommonParameters>]
#
Parameter set: Writer
Use-ConsoleTarget [-Colors <Ansi16|Ansi256|TrueColor>] [-Glyphs <Ascii|Basic|Full>] [-ScriptBlock] <ScriptBlock> -Target <ITerminalTarget> [-Width <Int32>] [<CommonParameters>]
#
Parameter set: Target

Description

Runs a script block with ConsoleMonster output going somewhere else: a file, a text writer, any target, or a string.

Inside the script block every ConsoleMonster command (Write-ConsoleText, Format-ConsoleTable, Write-ConsoleMarkup, live dashboards, prompts) writes to the target instead of the console. With -Path the output goes to a UTF-8 file, with -Writer to a TextWriter, with -Target to a target object (ConsoleMonster.Output.ITerminalTarget); with none of them it is returned as one string. -Width, -Glyphs and -Colors lay the output out for the file or string; prompts there have nobody to answer and use their defaults. The script block's own output is passed through.

Examples

Authored help example

EXAMPLE 1

Use-ConsoleTarget -ScriptBlock { }

EXAMPLE 2

Use-ConsoleTarget -ScriptBlock { } -Path 'C:\Path'

EXAMPLE 3

Use-ConsoleTarget -ScriptBlock { } -Target 'Value'

Parameters

-Colors ColorDepth optional
The colour depth for -Path, -Writer or the string (default None: plain text).
Possible values: Ansi16, Ansi256, TrueColor
-Glyphs GlyphTier optional
The glyph tier for -Path, -Writer or the string (default Ascii).
Possible values: Ascii, Basic, Full
-ScriptBlock ScriptBlock requiredposition: 0
The commands whose output goes to the target.
-Width Int32 optional
The width in cells for -Path, -Writer or the string (default 80).
-Append SwitchParameter optionalsets: Path
Appends to the file instead of replacing it.
-Path String requiredsets: Path
A file to write to (UTF-8 without a byte order mark; replaced unless -Append).
-Writer TextWriter requiredsets: Writer
A TextWriter to write to (it stays open).
-Target ITerminalTarget requiredsets: Target
A target object (ConsoleMonster.Output.ITerminalTarget).

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.