Hello,

I’m looking for some help with a PowerShell script. I need a script that will copy the primary SMTP proxyaddress into the mail attribute within AD. Since moving Exchange to Office 365, the E-Mail address field in the General Tab for an AD user doesn’t get populated anymore.

Any help would be greatly appreciated.

Thanks.

3 Spice ups

What have you tried so far?

1 Spice up

Found a way to do this. Below is my script for one user. Shouldn’t be difficult to run this across the domain or certain OU at this point.

$User = “test.test”
$address = Get-ADUser $user -Properties proxyAddresses | Select -Expand proxyAddresses | Where {$_ -clike “SMTP:*”}
$address = $address.SubString(5)
Set-ADUser $user -Email $address

Hope this helps someone else.

This will be more effective for entire users

$Users = Get-ADUser -Filter {proxyAddresses -like '*'} -Properties  proxyAddresses | Select sAMAccountName, proxyAddresses
ForEach ($User In $Users)
{
    $Name = $User.sAMAccountname
    $Addresses = $User.proxyAddresses
    ForEach ($Address In $Addresses)
    {
        If ($Address -cmatch "SMTP:")
        {
         $ad=$Address.SubString(5)
            set-aduser $name -mail $ad
        }
    }
}
1 Spice up

Also, If you post code, please use the ‘Insert Code’ button. Please and thank you!

@joeymartinez