This will show you how to step forward if you would like to set the targetAddress for all users within an Active Directory OU, to the primary SMTP address from the proxyAddresses attribute.
STEP 1: Update the script with the right OU, something like:
Get-ADUser -SearchBase "OU=Europe,CN=Users,DC=corp,DC=contoso,DC=com"
STEP 2: Start PowerShell as an Admin on the local network with access to the local Active Directory. Import the ActiveDirectory module and run the script.
Import-Module ActiveDirectory .\Script.ps1
(You might have to update execution policy!)
//xostmoen – Alexander Østmoen
# xostmoen # This script get all users in AD from a specified OU and all sub-OU's # It also fetches the ProxyAddresses from the object Get-ADUser -SearchBase "OU" -Filter * -Properties ProxyAddresses | foreach { $proxyAddress = $_ | Select -ExpandProperty ProxyAddresses | ? {$_ -clike "SMTP:*"} #For each user, we find the primary SMTP address, and set this to be the new targetAddress Set-ADuser $_ -Add @{targetAddress="$proxyAddress"} }