How to remove Proxy Addresses using Powershell

There is a requirement as part of domain migrations, that none of the domains being released can be referenced in the ProxyAddresses attribute using SIP or SMTP.

In order to tackle this requirement I created a powershell script to remove the proxy addresses that use any of the domains which are being removed as part of the domain migration.

To be able to use this script, i was required to compile a csv that contained the samaccountname and proxy address that i wanted to remove. I would do this for each user and proxy address.

Follow this link for a guide on How to export SIP and SMTP proxy addresses using Powershell.

Refer to the image below for an example of how your csv should look.

Once you have your csv formatted similar to the image above, we can run the script against it which will remove the proxy address from the account listed beside it.

#Import csv 
$emails = import-csv C:\Temp\Migration\Test.csv
#For each object in the csv, it will print the samaccountname and proxy address, I have added these for the sole reason of validating the addresses that will be removed.
$emails | ForEach-Object {
    Write-Output $_.samaccountName
    Write-Output $_.ProxyAddresses
    
#This will get the proxyaddress and convert it to a string
    [string]$Address = $_.ProxyAddresses
#this will validate it one more time before removing the proxyaddress
    Write-output "Validating: $Address"
    Set-ADUser -Identity $_.samaccountName -remove @{ ProxyAddresses = $Address } -Debug -Verbose
    }

Hopefully this script can prove useful to you!

If you have any questions please feel free to comment and ill do what i can to help.

Thank you for reading.

1 Reply to “How to remove Proxy Addresses using Powershell”

Leave a Reply to Tay Kratzer Cancel reply

Your email address will not be published.