Home
Check for uppercase email addresses and update it
Active Directory (PowerShell) Thursday, 18 June 2020 by paul

The following PowerShell script will check if any Active Directory users have an email address which contains an upper case character and will change all the email address to lowercase.

# Check email address is lowercase and update if not
Import-Module ActiveDirectory

$arrac = get-aduser -filter * -property SamAccountName, emailaddress

function CheckUpper {
   Param ($text)
   $c = 0
   $position = foreach ($character in $text.ToCharArray())
   {
     $c++
     if ([Char]::IsUpper($character))
     {
       return $c;
     }
   }
   return 0;
}

foreach($user in $arrac)
 {
    If ($user.EmailAddress -ne $null) {
        $sam = $user.SamAccountName
        $email = $user.EmailAddress
		if (CheckUpper($email) -gt 0) {
           $email2 = $user.EmailAddress.Tolower()
		   Write-host $sam "contains uppercase. converting $email -> $email2" -foreground red
           Set-ADUser -identity "$sam" -EmailAddress $email2
		}
		else {
		   Write-host $sam "only lowercase - $email" -foreground green
		}
    }
}

Needs to be run as a user with access to update the specified AD users.


Add Comment
No Comments.