PowerShell: Find users in AD with mis-match email address and UPN
Clear-Host
$usergroup = Get-ADUser -SearchBase "OU=Int,DC=lab,DC=com" -Filter {(Enabled -eq 'True')} -Properties DisplayName, Department, EmailAddress, mail, SamAccountName, UserPrincipalname
foreach ($user in $usergroup)
{
if ($user.EmailAddress -ne $user.UserPrincipalName)
{
Write-Output $user.DisplayName | Out-File -FilePath C:\Temp\Output.txt -Append -NoClobber
}
}