Format-ConsoleCode
Shows source text with syntax highlighting, line numbers and highlighted lines.
Syntax
Format-ConsoleCode [-AsWidget] [-FirstLine <Int32>] [-Highlight <String[]>] [[-InputObject] <Object>] [-Language <String>] [-LineNumbers] [-MaxLines <Int32>] [-NoTitle] [-Title <String>] [-Width <Int32>] [-Wrap] [<CommonParameters>]#TextFormat-ConsoleCode [-AsWidget] [-FirstLine <Int32>] [-Highlight <String[]>] [-Language <String>] [-LineNumbers] [-MaxLines <Int32>] [-NoTitle] -Path <String> [-Title <String>] [-Width <Int32>] [-Wrap] [<CommonParameters>]#PathDescription
Shows source text with syntax highlighting, line numbers and highlighted lines.
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
Format-ConsoleCode -AsWidgetEXAMPLE 2
Format-ConsoleCode -Path 'C:\Path'Parameters
- -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.