Skip to content
ConsoleMonster
Cmdlet

Compare-ConsoleObject

Module
ConsoleMonster
Inputs
System.Object[]
Outputs
ConsoleMonster.Changes.ObjectChange ConsoleMonster.Changes.BaselineRow ConsoleMonster.Changes.ChangeView ConsoleMonster.Changes.BaselineView System.Boolean

Compares object sets or shows property drift across a baseline matrix.

Syntax

Compare-ConsoleObject
[-AsWidget]
[-CaseSensitive]
[-CompareProperty <String[]>]
[-Depth <Int32>]
[-DifferenceObject] <Object[]>
[-Ignore <String[]>]
[-IncludeUnchanged]
[-Key <String[]>]
[-Normalize <Hashtable>]
[-PassThru]
[-ReferenceObject] <Object[]>
[-Title <Object>]
[-View <ChangeViewMode>]
[<CommonParameters>]
#
Parameter set: Compare
Compare-ConsoleObject
[-CaseSensitive]
[-CompareProperty <String[]>]
[-Depth <Int32>]
[-DifferenceObject] <Object[]>
[-Force]
[-Ignore <String[]>]
[-IncludeUnchanged]
[-Key <String[]>]
[-Normalize <Hashtable>]
[-NoTypedWhenDestructive]
-Question <String>
[-ReferenceObject] <Object[]>
[-Title <Object>]
[-TypedConfirmation <String>]
[-View <ChangeViewMode>]
[<CommonParameters>]
#
Parameter set: Confirm
Compare-ConsoleObject
[-AsWidget]
[-Baseline <Object>]
[-CaseSensitive]
[-CompareProperty <String[]>]
[-Depth <Int32>]
[-Ignore <String[]>]
[-IncludeUnchanged]
-InputObject <Object[]>
[-Key <String[]>]
[-Name <String[]>]
[-Normalize <Hashtable>]
[-PassThru]
[-Title <Object>]
[-View <ChangeViewMode>]
[<CommonParameters>]
#
Parameter set: Baseline

Description

ReferenceObject and DifferenceObject are matched by Key (or Id, Key, Name and similar members), then compared by nested property path. Keys and string values compare case-insensitively by default; CaseSensitive applies to both. Case-only differences remain visible with IsCaseOnly and do not increase changed counts. Missing properties use a localized marker, distinct from present null or empty values. Normalize maps exact paths to scriptblocks receiving $_ or $PSItem; comparison uses their results while display retains the originals. Full, Summary, Table, SideBySide and Unified show two-set comparisons, including line diffs of long values. InputObject selects a baseline matrix with one property per row and one object per column. Baseline chooses a column by name or zero-based integer index; Name or Key sets headings. Equal rows are hidden unless IncludeUnchanged is set; case-only rows remain visible. PassThru returns ObjectChange records or BaselineRow records without drawing. AsWidget returns an IWidget for Show-ConsoleApp layouts and Export-ConsoleFrame.

Examples

Example 1

$before = @([pscustomobject]@{ Name = 'web01'; Port = 80 })
$after = @([pscustomobject]@{ Name = 'web01'; Port = 443 })
$objectOptions = @{
    ReferenceObject = $before
    DifferenceObject = $after
    Key = @('Name')
}
Compare-ConsoleObject @objectOptions

Compare two small inventories

Example 2

$before = @([pscustomobject]@{ Name = 'web01'; Port = 80 })
$after = @([pscustomobject]@{ Name = 'web01'; Port = 443 })
$objectOptions = @{
    ReferenceObject = $before
    DifferenceObject = $after
    Key = @('Name')
    Question = 'Accept these changes?'
}
$accepted = Compare-ConsoleObject @objectOptions
$accepted

Ask before accepting a configuration change

Example 3

$controllers = @(
    [pscustomobject]@{ Name = 'dc01'; Site = 'HQ'; LdapPort = 389 }
    [pscustomobject]@{ Name = 'dc02'; Site = 'HQ'; LdapPort = 636 }
    [pscustomobject]@{ Name = 'dc03'; Site = 'Branch'; LdapPort = 636 }
)
$objectOptions = @{
    View = 'Baseline'
    Key = @('Name')
    Baseline = 'dc02'
    Ignore = @('Name')
    Title = 'Domain controllers'
}
$controllers | Compare-ConsoleObject @objectOptions

Compare three domain controller settings against dc02.

Example 4

$normalizers = @{ ServicePrincipalName = { $_ -replace 'dc[0-9]+', 'HOST' } }
$objectOptions = @{
    AsWidget = $true
    ReferenceObject = $before
    DifferenceObject = $after
    Key = @('Name')
    Normalize = $normalizers
}
$widget = Compare-ConsoleObject @objectOptions
$frameOptions = @{
    Format = 'Html'
    Width = 120
    Path = './comparison.html'
}
$widget | Export-ConsoleFrame @frameOptions

Normalize host-specific noise while retaining the original displayed values.

Parameters

-AsWidget SwitchParameter optionalsets: Compare, Baseline
Returns a composable ChangeView or BaselineView without drawing. Cannot be combined with PassThru or Question.
-CaseSensitive SwitchParameter optional
Compares both match keys and string values with ordinal case sensitivity. By default case-only differences remain visible but do not increase changed counts.
-CompareProperty String[] optional
The properties to compare (default all).
-Depth Int32 optional
How deep nested objects are compared (default 3).
-DifferenceObject Object[] requiredposition: 1pipeline: True (ByValue)sets: Compare, Confirm
The new objects.
-Ignore String[] optional
Properties or paths (Address.City, wildcards) left out of the comparison.
-IncludeUnchanged SwitchParameter optional
Lists unchanged objects or baseline rows too. Case-only differences are always visible.
-Key String[] optional
The properties that identify an object (matching key). Default: Id, Key, Name and similar members.
-Normalize Hashtable optional
A hashtable of exact property paths to comparison-only scriptblocks. Each receives its original value as $_ and $PSItem. Display and structured values remain original.
-PassThru SwitchParameter optionalsets: Compare, Baseline
Returns the changes as objects instead of showing them.
-ReferenceObject Object[] requiredposition: 0sets: Compare, Confirm
The old objects.
-Title Object optional
A title (markup).
-View ChangeViewMode optional
The view: Full (default), Summary, Table, SideBySide, Unified or Baseline (with InputObject).
Possible values: Full, Summary, Table, SideBySide, Unified, Baseline
-Force SwitchParameter optionalsets: Confirm
Accepts a nonempty change set without asking. WhatIf still returns false.
-NoTypedWhenDestructive SwitchParameter optionalsets: Confirm
Uses a yes/no question for removals unless TypedConfirmation is supplied.
-Question String requiredsets: Confirm
Shows the changes, asks this question and returns a Boolean answer.
-TypedConfirmation String optionalsets: Confirm
Text that must be typed to confirm the preview.
-Baseline Object optionalsets: Baseline
The reference column name or zero-based integer index. Default zero. A numeric string is a name.
-InputObject Object[] requiredpipeline: True (ByValue)sets: Baseline
Two or more objects to compare as a baseline matrix, in column order. Accepts pipeline input.
-Name String[] optionalsets: Baseline
One explicit column name per input object.

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.