Compare-ConsoleObject
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>]#CompareCompare-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>]#ConfirmCompare-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>]#BaselineDescription
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 @objectOptionsCompare 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
$acceptedAsk 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 @objectOptionsCompare 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 @frameOptionsNormalize host-specific noise while retaining the original displayed values.
Parameters
- -AsWidget SwitchParameter
- Returns a composable ChangeView or BaselineView without drawing. Cannot be combined with PassThru or Question.
- -CaseSensitive SwitchParameter
- 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[]
- The properties to compare (default all).
- -Depth Int32
- How deep nested objects are compared (default 3).
- -DifferenceObject Object[]
- The new objects.
- -Ignore String[]
- Properties or paths (Address.City, wildcards) left out of the comparison.
- -IncludeUnchanged SwitchParameter
- Lists unchanged objects or baseline rows too. Case-only differences are always visible.
- -Key String[]
- The properties that identify an object (matching key). Default: Id, Key, Name and similar members.
- -Normalize Hashtable
- 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
- Returns the changes as objects instead of showing them.
- -ReferenceObject Object[]
- The old objects.
- -Title Object
- A title (markup).
- -View ChangeViewMode
- The view: Full (default), Summary, Table, SideBySide, Unified or Baseline (with InputObject).
- Possible values:
Full,Summary,Table,SideBySide,Unified,Baseline - -Force SwitchParameter
- Accepts a nonempty change set without asking. WhatIf still returns false.
- -NoTypedWhenDestructive SwitchParameter
- Uses a yes/no question for removals unless TypedConfirmation is supplied.
- -Question String
- Shows the changes, asks this question and returns a Boolean answer.
- -TypedConfirmation String
- Text that must be typed to confirm the preview.
- -Baseline Object
- The reference column name or zero-based integer index. Default zero. A numeric string is a name.
- -InputObject Object[]
- Two or more objects to compare as a baseline matrix, in column order. Accepts pipeline input.
- -Name String[]
- 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.