Functions/Compare-MSPCompleteUsers.ps1

<#
.SYNOPSIS
    This function performs a comparison between two lists of MSPComplete users
.DESCRIPTION
    This function performs a comparison between two lists of MSPComplete users.
    It returns true if both lists contain the same set of users with matching property
    and extended property values, and false otherwise.
#>

function Compare-MSPCompleteUsers {
    param (
        # The users used as the reference objects.
        [Parameter(Mandatory=$true)]
        [AllowEmptyCollection()]
        [Object[]]$referenceUsers,

        # The users used as the comparison objects.
        [Parameter(Mandatory=$true)]
        [AllowEmptyCollection()]
        [Object[]]$comparisonUsers
    )

    # Check if list of users is identical
    if ($referenceUsers.length -ne $comparisonUsers.length) {
        Write-Error "Lengths of user lists are different: $($referenceUsers.length) and $($comparisonUsers.length)."
        return $false
    }

    # Sort users by the PrimaryEmailAddress property
    $referenceUsers = $referenceUsers | Sort-Object -Property PrimaryEmailAddress
    $comparisonUsers = $comparisonUsers | Sort-Object -Property PrimaryEmailAddress

    # Run through users to compare
    for ($i = 0; $i -lt $referenceUsers.length; ++$i) {
        if (!(Compare-MSPCompleteUser -ReferenceUser $referenceUsers[$i] -ComparisonUser $comparisonUsers[$i])) {
            return $false
        }
    }

    # Users match
    return $true
}