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 and others will put 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 = $
    $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}

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.