Skip to content

Compare-PSCustomObject

SYNOPSIS

Compare two PSCustomObjects and return the comparison.

SYNTAX

Compare-PSCustomObject -Left <Object> [-Right] <Object> [-OnlyChanged] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

This function compares two PSCustomObjects and returns an overview of the differences. It can also filter to show only the properties that have changed.

EXAMPLES

EXAMPLE 1

Compare-PSCustomObject -Left $object1 -Right $object2 -OnlyChanged

EXAMPLE 2

$object1 = [PSCustomObject]@{
    Name  = 'Test'
    Value = 1
}
$object2 = [PSCustomObject]@{
    Name  = 'Test'
    Value = 2
}
$object1 | Compare-PSCustomObject $object2

Output:

Property Left Right Changed
-------- ---- ----- -------
Name     Test Test    False
Value    1    2        True

PARAMETERS

-Left

The left object to compare

Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Right

The right object to compare

Type: Object
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-OnlyChanged

Only show properties that have changed

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

https://psmodule.io/PSCustomObject/Functions/Compare-PSCustomObject