Skip to content
ConsoleMonster
Cmdlet

Use-ConsoleTarget

Module
ConsoleMonster

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

Syntax

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

Description

Inside the script block every ConsoleMonster command (Write-ConsoleText, Show-ConsoleTable, Write-ConsoleText -Markup, 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 -ColorDepth 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

Example 1

$targetOptions = @{
    Width = 120
    ScriptBlock = { Get-Process | Select-Object -First 5 Name, Id | Show-ConsoleTable; Write-ConsoleText -Markup '[pass]done[/]' }
}
Use-ConsoleTarget @targetOptions

Capture a report as plain text

Example 2

$targetOptions = @{
    Width = 80
    ScriptBlock = { Get-Process | Select-Object -First 5 | Show-ConsoleTable }
}
$text = Use-ConsoleTarget @targetOptions

Capture a table as a string

Parameters

-ColorDepth 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 0: terminal width, falling back to 100).
-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.