Show-ConsoleCode
Shows source text with syntax highlighting, line numbers and highlighted lines.
Syntax
Show-ConsoleCode
[-AsString]
[-AsWidget]
[-FirstLine <Int32>]
[-Highlight <String[]>]
[[-InputObject] <Object>]
[-Language <String>]
[-LineNumbers]
[-MaxLines <Int32>]
[-NoTitle]
[-Title <String>]
[-Width <Int32>]
[-Wrap]
[<CommonParameters>]#TextShow-ConsoleCode
[-AsString]
[-AsWidget]
[-FirstLine <Int32>]
[-Highlight <String[]>]
[-Language <String>]
[-LineNumbers]
[-MaxLines <Int32>]
[-NoTitle]
-Path <String>
[-Title <String>]
[-Width <Int32>]
[-Wrap]
[<CommonParameters>]#PathDescription
Highlights JSON, XML/HTML, YAML, PowerShell, C#, SQL, INI/TOML, CSV/TSV, diffs, log lines and Markdown, or plain text with -Language Smart (numbers, booleans, GUIDs, IP addresses, URLs, paths, dates, DNs, quoted strings). -Language Auto (the default) picks the language from the file extension, then from the content, and falls back to plain text. Text comes from -Path or from pipeline strings (joined as lines). The text is always literal: markup is not read and control characters are dropped. -LineNumbers adds a gutter, -Highlight marks lines (10, '10-14'), long lines are truncated with an ellipsis or wrapped with -Wrap, and output stops after -MaxLines lines with "+n more lines". A file is shown on a panel titled with its name (-Title changes it, -NoTitle leaves the panel out). Redirected output is plain text.
Examples
Example 1
Show-ConsoleCode -Path .\deploy.ps1 -LineNumbers -Highlight '12-13'A script with line numbers and two lines marked
Example 2
Get-Content .\agent.log -Tail 20 | Show-ConsoleCode -Language LogA log file's last lines
Parameters
- -AsString SwitchParameter
- Writes the view as one string of plain text instead of drawing it, to keep it in a variable or a file from any script, function or PowerShell version. Without it, PowerShell 7.2+ captures a view typed at the prompt ($x = ..., > file, Out-File); inside scripts and functions, and on Windows PowerShell 5.1, the view is drawn on the screen. Piped into another command (Out-Host, Out-String, Select-String) the view goes on as plain lines, without colour. Cannot be combined with -PassThru.
- -AsWidget SwitchParameter
- Returns the view instead of writing it.
- -FirstLine Int32
- The number of the first line (default 1), for excerpts.
- -Highlight String[]
- Lines to mark: numbers or ranges such as 10, '10-14'.
- -InputObject Object
- Text to show (pipeline strings are joined as lines).
- -Language String
- The language: Auto (default), Json, Xml, Yaml, PowerShell, CSharp, Sql, Ini, Csv, Diff, Log, Markdown, Smart, Text, or a language registered from C#.
- -LineNumbers SwitchParameter
- Shows line numbers.
- -MaxLines Int32
- The most lines shown (default 2000).
- -NoTitle SwitchParameter
- Leaves the panel out.
- -Title String
- The panel title (default the file name with -Path; none for pipeline text).
- -Width Int32
- Lays the output out for this width instead of the terminal's.
- -Wrap SwitchParameter
- Wraps long lines instead of truncating them.
- -Path String
- A file to show.
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.