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")