Functions/Compare-ActiveDirectoryUsers.ps1

<#
.SYNOPSIS
    This function compares two Active Directory user objects and returns if the objects are equivalent.
#>

function Compare-ActiveDirectoryUsers {
    [CmdletBinding(PositionalBinding=$false)]
    [OutputType([Boolean])]
    param (
        # The Active Directory user used as the reference object.
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [PSObject]$referenceUser,

        # The Active Directory user used as the comparison object.
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [PSObject]$comparisonUser,

        # Select the stream where the messages will be directed.
        [Parameter(Mandatory=$false)]
        [ValidateSet("Information", "Warning", "Error", "None")]
        [String]$outputStream = "Error"
    )

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

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

    # The two objects are the same
    return $true
}