0 votes

We have been able to add email addresses using the script in E-Mail Addresses Is there a way to reverse the process and specify the smtp address you want to remove using a similar subset of code.

by (40 points)

1 Answer

0 votes
by (14.1k points)

Hello Martin,

Please, find the script that removes the specified email address from the list of email addresses. In the script:

  • $userDN - Specifies a distinguished name of the user whose list of email addresses will be modified.
  • $addressToRemove - Specifies the address that will be removed.
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$userDN =  "CN=John Doe,OU=Users,DC=domain,DC=com" # TODO: modify me
$addressToRemove = "john.doe@domain.com" # TODO: modify me

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Get the list of email addresses
$mailboxParams = $user.GetMailParameters()
$emailAddresses = $mailboxParams.EmailAddresses

# Remove the e-mail address from the list of existing addresses
$emailAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = $addressToRemove

$emailAddresses.Remove($emailAddress)
$mailboxParams.EmailAddresses = $emailAddresses

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")

Related questions

0 votes
1 answer

After creating a new user I'm modifying the user and setting 2 proxy addresses. I'm doing this with the build-in modify user functionality. Our email format is %firstname%. ... anybody have an idea to get this working, i'm not as Powershell wizzard...

asked Oct 15, 2018 by Quinten (100 points)
0 votes
1 answer

I'm trying to modify mailbox settings to add additional email addresses to a user after creation. This is a hybrid on-prem and Exchange Online with E5 licenses. Everything works up ... to a different OU during the process so I know the user exists. Any ideas?

asked Mar 6, 2023 by Michael Long (70 points)
0 votes
1 answer

Hi all I need to modify the template $remoteRoutingAddressTemplate with the default exchange option automatically update email addresses disable. How i make it?

asked Nov 28, 2022 by Simone.Vailati (430 points)
+1 vote
1 answer

Since today were receiving the below error when attempting to add additional email addresses to users via Adaxes. An Azure Active Directory call was made to keep object in sync ... How do we fix to get the ability to add email addresses via Adaxes again?

asked Mar 1, 2021 by techg (320 points)
0 votes
1 answer

Hello, I have created a business rule to create Office 365 Mailboxes and set certain properties: adm-customattributeBoolean1 has a friendly name of "create Exchange Online mailbox?" adm- ... out the SMTP values created by my rule. How to I get around this?

asked Feb 23, 2015 by DFassett (710 points)
3,548 questions
3,238 answers
8,232 comments
547,811 users