/ Powershell

Replace a proxyAddress in AD with Powershell

Today I came across a problem (caused by my own typo earlier) where some users had the wrong proxyAddress.

Instead of "smtp:[userName]@[domain]" they had "smtp:[userName][domain]" and before you ask - yes, you do need a @ for email addresses ;).

So my solution was to do the following:

#$AllUsersToFix = an array of ADUsers with the proxyAddressesProperty

foreach ($user in $AllUsersToFix)
{
    $fixed = $user.proxyaddresses | % {
        if ($_ -eq "smtp:{0}domain.se" -f $user.name)
        {
            "smtp:{0}@domain.se" -f $user.name
        }
        else
        {
            $_.ToString() #or it won't work
        }
    }
    Set-ADUser $user -Replace @{proxyaddresses=$fixed}
}

A neat little trick to have for future problems :)

Andreas Selevik

Andreas Selevik

Solution Architect specialized in Windows & Azure Architecture, Office 365, PowerShell, Identity management and automation. Manchester United fanatic, father, husband and a very good winner...

Read More