# Update Proxyaddresses in local AD

**URL:** <https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341>\
**Category:** PowerShell Help\
**Created:** [May 18, 2022, 9:05am UTC](https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341 "2022-05-18T09:05:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cantercrow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/cantercrow/32/2379_2.png) [@cantercrow](https://forums.powershell.org/u/cantercrow)\
**Post date:** [May 18, 2022, 9:05am UTC](https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341/1 "2022-05-18T09:05:41Z")

</div>

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.

```auto
$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"}

}

```

---

<div class="post-metadata">

**Author:** ![laage](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/laage/32/43_2.png) [@laage](https://forums.powershell.org/u/laage)\
**Post date:** [May 18, 2022, 11:15am UTC](https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341/2 "2022-05-18T11:15:05Z")

</div>

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.

```auto
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"}
}

```

---

<div class="post-metadata">

**Author:** ![cantercrow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/cantercrow/32/2379_2.png) [@cantercrow](https://forums.powershell.org/u/cantercrow)\
**Post date:** [May 18, 2022, 11:49am UTC](https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341/3 "2022-05-18T11:49:56Z")

</div>

Thank you did not notice that, working now.

Thanks

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:17pm UTC](https://forums.powershell.org/t/update-proxyaddresses-in-local-ad/19341/4 "2024-05-16T20:17:58Z")

</div>


