Categories
Auditing Powershell

Auditing: Format Active Directory Email Addresses

Perhaps this is just my own OCD but I think email addresses should all be formatted in the same way in active directory but inevitably some will put john@company.com and others will put John@company.com and all variations in between. 

The below can be run to fix the formatting as you like it and will change all email addresses to your desired format.

$users = Get-ADUser -filter * -Properties name,samaccountname,mail  | Select-Object name,samaccountname,mail
foreach ($user in $users) {

    $Name = $user.name
    $UserID = $user.samaccountname
    $Email = $user.mail
    $NewEmail = (Get-Culture).TextInfo.ToTitleCase("$email")
try {
set-aduser $UserID -EmailAddress $NewEmail 
}
catch {write-host "The email field for $Name is blank" -ForegroundColor Red}
}
$users.Count

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.