Use-ConsoleTarget
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>]#StringUse-ConsoleTarget
[-Append]
[-ColorDepth <Ansi16| Ansi256| TrueColor>]
[-Glyphs <Ascii| Basic| Full>]
-Path <String>
[-ScriptBlock] <ScriptBlock>
[-Width <Int32>]
[<CommonParameters>]#PathUse-ConsoleTarget
[-ColorDepth <Ansi16| Ansi256| TrueColor>]
[-Glyphs <Ascii| Basic| Full>]
[-ScriptBlock] <ScriptBlock>
[-Width <Int32>]
-Writer <TextWriter>
[<CommonParameters>]#WriterUse-ConsoleTarget
[-ColorDepth <Ansi16| Ansi256| TrueColor>]
[-Glyphs <Ascii| Basic| Full>]
[-ScriptBlock] <ScriptBlock>
-Target <ITerminalTarget>
[-Width <Int32>]
[<CommonParameters>]#TargetDescription
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 @targetOptionsCapture a report as plain text
Example 2
$targetOptions = @{
Width = 80
ScriptBlock = { Get-Process | Select-Object -First 5 | Show-ConsoleTable }
}
$text = Use-ConsoleTarget @targetOptionsCapture a table as a string
Parameters
- -ColorDepth ColorDepth
- The colour depth for -Path, -Writer or the string (default None: plain text).
- Possible values:
Ansi16,Ansi256,TrueColor - -Glyphs GlyphTier
- The glyph tier for -Path, -Writer or the string (default Ascii).
- Possible values:
Ascii,Basic,Full - -ScriptBlock ScriptBlock
- The commands whose output goes to the target.
- -Width Int32
- The width in cells for -Path, -Writer or the string (default 0: terminal width, falling back to 100).
- -Append SwitchParameter
- Appends to the file instead of replacing it.
- -Path String
- A file to write to (UTF-8 without a byte order mark; replaced unless -Append).
- -Writer TextWriter
- A TextWriter to write to (it stays open).
- -Target ITerminalTarget
- 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.