0 votes

Hallo,
In the deprovisioning process we add "_" to each email addresses like you see on below script:

# Get mailbox parameters
$mailboxParams = $Context.TargetObject.GetMailParameters()

# Change email adresses
$mailboxParams.EmailAddressPolicyEnabled = $False
$emailAddresses = $mailboxParams.EmailAddresses
for ($i = 0; $i -lt $emailAddresses.Count; $i++)
{
    $emailAddress = $emailAddresses.GetAddress($i,[ref]"ADS_PROPERTY_NONE")
    $emailAddress.Address = "_" + $emailAddress.Address
}
$mailboxParams.EmailAddresses = $emailAddresses

But sometimes we have user has X400 an X500 addresses we would like to remove those addresses, how can I do it using Adaxes SDK?

by (510 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

Like this:

$prefixes = @("x400", "x500") # TODO: modify me

# Get mailbox parameters
$mailboxParams = $Context.TargetObject.GetMailParameters()

# Remove Address with the specified prefixes
$mailboxParams.EmailAddressPolicyEnabled = $False
$emailAddresses = $mailboxParams.EmailAddresses
foreach ($prefix in $prefixes)
{
    foreach ($emailAddress in $emailAddresses.GetAddressesByPrefix($prefix))
    {
        $emailAddresses.Remove($emailAddress)
    }
}

# Change email addresses
for ($i = 0; $i -lt $emailAddresses.Count; $i++)
{
    $emailAddress = $emailAddresses.GetAddress($i,[ref]"ADS_PROPERTY_NONE")
    $emailAddress.Address = "_" + $emailAddress.Address
}
$mailboxParams.EmailAddresses = $emailAddresses

# Save changes
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
0

And what if I'd like to change only SMTP addresses, without any changes on X500 and X400?
I mean we add "_" to all SMTP but left X400 and X500 without ant chanes.

0

Sure:

# Get mailbox parameters
$mailboxParams = $Context.TargetObject.GetMailParameters()

# Change SMTP email addresses
$mailboxParams.EmailAddressPolicyEnabled = $False
$emailAddresses = $mailboxParams.EmailAddresses
foreach ($emailAddress in $emailAddresses.GetAddressesByPrefix("SMTP"))
{
    $emailAddress.Address = "_" + $emailAddress.Address
}
$mailboxParams.EmailAddresses = $emailAddresses

# Save changes
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Related questions

0 votes
1 answer

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.

asked Dec 14, 2022 by martin.mcclorey (40 points)
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

Hi, I need to create a number of mail user accounts via Adaxes and a lot of these accounts have & in the displayname/email address etc (I know, I know ... failed so I can troubleshoot it better. I have tried $context.logmessage($_.Exception.Message) Thanks

asked May 9 by typod (50 points)
0 votes
1 answer

Hi, would it be possible to script a workstation in AD and also directly from our local SCCM environment ?

asked Oct 28 by ddesmedt (40 points)
0 votes
1 answer

This may sound a little convoluted, but I will try and explain. I'd like to have an operation require approval by a group. And if the initiator is a member of that group, I don ... into it at a new company. I've got to dust off some of the brain cells. Thanks.

asked Jul 17 by wd.swaters (40 points)
3,548 questions
3,238 answers
8,232 comments
547,813 users