Update Proxyaddresses in local AD

Good day,

I need to swap around 200 users’ primary SMTP as below

Current
SMTP:usernameATdomain1.co.uk
smtp:usernameATdomain2.co.uk

Change to
SMTP:usernameATdomain2.co.uk
smtp:usernameATdomain1.co.uk

This is what I have so far but it does not error and does to change anything.

$ASLUsers = Get-ADUser -Filter * -SearchBase "OU=Testing,OU=Permanent-SSC,OU=ASLSSC,OU=staff,DC=asl,DC=lan"
foreach($ASLUsers in $ASLUsers)
{
Set-ADUser -Identity $ASLUsers.samaccountname -remove @{Proxyaddresses="SMTP:" + $ASLUsers.samaccountname + "ATdomain1.co.uk"}

Set-ADUser -Identity $ASLUsers.samaccountname -remove @{Proxyaddresses="SMTP:" + $ASLUsers.samaccountname + "ATdomain2.co.uk"}

}

Hi Cantercrow and welcome to the forum.

I’m pretty sure that the problem is that you are using the entire array of users in the foreach instead of one user at the time.

Change the script to this and I think you will have better luck.

foreach ($user in $ASLusers) {
  Set-ADUser -Identity $user.samaccountname -remove @{Proxyaddresses="SMTP:" + $user.samaccountname + "ATdomain1.co.uk"}

  Set-ADUser -Identity $user.samaccountname -remove @{Proxyaddresses="SMTP:" + $user.samaccountname + "ATdomain2.co.uk"}
}
1 Like

Thank you did not notice that, working now.

Thanks