Functions/Compare-MSPCompleteUser.ps1

<#
.SYNOPSIS
    This function performs a comparison between a reference user object and a comparison user object.
.DESCRIPTION
    This function performs a comparison between a reference user object and a comparison user object.
    It returns true if the objects match in both property values and extended property values,
    and false otherwise.
#>

function Compare-MSPCompleteUser {
    param (
        # The user used as the reference object.
        [Parameter(Mandatory=$true)]
        $referenceUser,

        # The user used as the comparison object.
        [Parameter(Mandatory=$true)]
        $comparisonUser
    )

    # Get list of properties to compare
    $propertiesToCompare = Get-MSPCompleteUserPropertyList

    # Compare properties
    foreach ($property in $propertiesToCompare) {
        if ($referenceUser.$property -ne $comparisonUser.$property) {
            Write-Error "Property '$($property)' does not match for user '$($referenceUser.DisplayName)' - Reference: '$($referenceUser.$property)' Comparison: '$($comparisonUser.$property)'"
            return $false
        }
    }

    # Get list of extended properties to compare
    $extendedPropertiesToCompare = Get-MSPCompleteUserExtendedPropertyList

    # Compare extended properties
    foreach ($property in $extendedPropertiesToCompare) {
        if ($referenceUser.ExtendedProperties.$property -ne $comparisonUser.ExtendedProperties.$property) {
            Write-Error "Extended property '$($property)' does not match for user '$($referenceUser.DisplayName)' - Reference: '$($referenceUser.ExtendedProperties.$property)' Comparison: '$($comparisonUser.ExtendedProperties.$property)'"
            return $false
        }
    }

    # The two objects are the same
    return $true
}