Skip to main content

Compare-UserAttribute

SYNOPSIS

Compare two user attributes from different sources.

SYNTAX

DESCRIPTION

This function compares two specified user attributes from Active Directory, Entra ID (Microsoft Graph), or Exchange. It can filter users based on email domain or specific user identities and returns users whose attributes either match or do not match. PowerShell 7 and Active Directory: PS365 requires PowerShell 7 or later. Source AD can still be used on Windows with the ActiveDirectory module supplied by compatible RSAT tools. Calling Get-ADUser does not inherently require PowerShell 5.1. For example, Microsoft lists the ActiveDirectory module on Windows Server 2019 with RSAT-AD-PowerShell as natively compatible with PowerShell 7. Import-Module ActiveDirectory -ErrorAction Stop loads it. If your installed AD module needs Windows PowerShell compatibility, run Import-Module ActiveDirectory -UseWindowsPowerShell -ErrorAction Stop from PowerShell 7 on Windows. This runs the module in a background Windows PowerShell 5.1 session and returns deserialized objects. Simple property comparisons generally work, but live AD object methods are not preserved. This does not provide ActiveDirectory support on Linux or macOS. Only Source AD needs this module, domain connectivity and appropriate AD read permissions. Source EntraID and Source Exchange do not depend on ActiveDirectory. The function does not install RSAT or explicitly select a compatibility mode; prepare the required module/session before calling it.

EXAMPLES

EXAMPLE 1

From PowerShell 7 on Windows with compatible RSAT tools, compares the ‘mail’ and ‘UserPrincipalName’ attributes in Active Directory and returns users whose values differ.

EXAMPLE 2

Compares the ‘userPrincipalName’ and ‘mail’ attributes for users in Entra ID and returns those with non-matching values.

PARAMETERS

-Attribute1

The first user attribute to compare.

-Attribute2

The second user attribute to compare.

-ByDomain

An array of email domains to filter users.

-Return

Specifies whether to return users with ‘Matching’ or ‘NotMatching’ attributes.

-Source

The source from which to retrieve user information. Valid options are ‘AD’ for Active Directory, ‘EntraID’ for Microsoft Entra ID, and ‘Exchange’ for Exchange.

-User

An array of user identities to filter the comparison.

CommonParameters

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

INPUTS

OUTPUTS

NOTES