Compare-ConsoleText
Compares text or files with numbered lines, highlighted words and collapsed unchanged regions.
Syntax
Compare-ConsoleText
[-AsUnified]
[-Context <Int32>]
[-DifferenceName <String>]
[-DifferenceText] <String>
[-IgnoreWhitespace]
[-ReferenceName <String>]
[-ReferenceText] <String>
[<CommonParameters>]#TextCompare-ConsoleText
[-AsUnified]
[-Context <Int32>]
[-DifferenceName <String>]
-DifferencePath <String>
[-IgnoreWhitespace]
[-ReferenceName <String>]
-ReferencePath <String>
[<CommonParameters>]#PathDescription
Shows the reference and difference side by side at 120 columns or more, and inline in narrower terminals. Text headings default to Before and After; file headings use the resolved filenames. ReferenceName and DifferenceName override these headings in both the widget and unified output. Minus and plus markers distinguish changes without colour. Context controls the unchanged lines around changes. CRLF, LF and CR endings compare equally; a missing final newline remains significant. Large inputs use bounded comparison work and linear auxiliary memory, so a large changed range may produce a non-minimal diff. AsUnified returns plain unified diff text instead of rendering.
Examples
Example 1
Compare-ConsoleText -ReferenceText $before -DifferenceText $after -Context 1Compare configuration strings with one line of context.
Example 2
Compare-ConsoleText -ReferencePath .\before.txt -DifferencePath .\after.txt -IgnoreWhitespaceCompare files using the current PowerShell location and ignore whitespace within lines.
Example 3
Compare-ConsoleText -ReferenceText $before -DifferenceText $after -ReferenceName 'Deployed' -DifferenceName 'Proposed' -AsUnified | Set-Content .\changes.diffReturn a unified diff with custom side names for storage or further processing.
Parameters
- -AsUnified SwitchParameter
- Returns a single plain unified diff string with LF separators and hunk ranges. Equal texts return an empty string. Without this switch, writes a widget to the host and returns no objects.
- -Context Int32
- The nonnegative number of unchanged lines shown before and after each change. Default three; zero shows changes only.
- -DifferenceName String
- The new-text heading in the widget and unified output. Overrides the resolved difference filename for files or After for text. Control characters are replaced by spaces.
- -DifferenceText String
- The new text. Empty strings and null represent an empty document.
- -IgnoreWhitespace SwitchParameter
- Ignores Unicode whitespace within lines. Line boundaries and a missing final newline are still compared.
- -ReferenceName String
- The original-text heading in the widget and unified output. Overrides the resolved reference filename for files or Before for text. Control characters are replaced by spaces.
- -ReferenceText String
- The original text. Empty strings and null represent an empty document.
- -DifferencePath String
- The new file's PowerShell path. The provider must be FileSystem and the path must resolve to exactly one readable file. Files are read as UTF-8 with BOM detection.
- -ReferencePath String
- The original file's PowerShell path, relative to the current location or qualified by a filesystem drive. Wildcards must resolve to exactly one file.
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.