We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Automatically update SIP address

February 18, 2021 Views: 7681

The script automatically sets a user's SIP address the same as the primary SMTP address.

To use the script with Adaxes, you need to create a business rule triggered after modifying Exchange properties of a user that runs the script using the Run a program or PowerShell script action.

For more information on modifying mailbox addresses using Adaxes ADSI API, see E-Mail Addresses.
Edit Remove
PowerShell
# Get Exchange properties
$mailboxParams = $Context.TargetObject.GetMailParameters()
$emailAddresses = $mailboxParams.EmailAddresses

# Get current SIP addresses
$sipAddresses = $emailAddresses.GetAddressesByPrefix("sip")
if ($sipAddresses.Length -eq 0)
{
    return # The user doesn't have a SIP address
}
elseif ($sipAddresses.Length -gt 1)
{
    $Context.LogMessage("Found more than one SIP address", "Warning")
    return
}

# Get primary SMTP address
$smtpAddresses = $emailAddresses.GetAddressesByPrefix("smtp")
foreach ($smtpAddress in $smtpAddresses)
{
    if (-not($smtpAddress.IsPrimary))
    {
        continue
    }
    $primaryAddress = $smtpAddress.Address
    break
}

# Compare Primary SMTP and SIP addresses
$sipAddress = $sipAddresses[0]
if ($sipAddress -ieq $primaryAddress)
{
    return # Primary SMTP address was not changed
}

# Change SIP Address
$sipAddress.Address = $primaryAddress

# Save changes
$mailboxParams.EmailAddresses = $emailAddresses
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
Comments 6
avatar
Thomas Aug 09, 2023
Hi there!
Is there a version of this script available that can automatically set the SIP address to match the primary SMTP address if the SIP address is missing? Currently, it appears that the script doesn't perform this action if any predefined SIP addresses are already present.
avatar
Support Aug 09, 2023
Hello Thomas,

Currently, the script exists if there are no SIP addresses present or there is more than one SIP address. For the first case you need to just create a SIP address matching the primary SMTP one. What about the second case? What should be done then?
avatar
Thomas Aug 09, 2023
Hello!
When I run it on a user without SIP, there is no SIP after.
When I run it on a user with SIP, it update the SIP to the correct one.
The script don't create the SIP for me, only update if a SIP already is there.

Running Adaxes 2023 V3.15
avatar
Support Aug 09, 2023
Hello Thomas,

That is correct for the current script. It is written exactly this way. Do you want the script to just always create a SIP address matching the primary SMTP address no matter of the existing SIP addresses?
avatar
Thomas Aug 09, 2023
Hello!
Yes please. If a SIP is present update to primary SMTP, if no SIP set it same as primary SMTP.
So there is only one SIP present at the user.

Thank you!
avatar
Support Aug 09, 2023
Hello Thomas,

Thank you for the confirmation. Here is the script.

Edit Remove
PowerShell
# Get Exchange properties
$mailboxParams = $Context.TargetObject.GetMailParameters()
$emailAddresses = $mailboxParams.EmailAddresses

# Get current SIP addresses
$sipAddresses = $emailAddresses.GetAddressesByPrefix("sip")
foreach ($sipAddress in $sipAddresses)
{
    $emailAddresses.Remove($sipAddress)
}

# Get primary SMTP address
$smtpAddresses = $emailAddresses.GetAddressesByPrefix("smtp")
foreach ($smtpAddress in $smtpAddresses)
{
    if (-not($smtpAddress.IsPrimary))
    {
        continue
    }
    $primaryAddress = $smtpAddress.Address
    break
}

# Create a new SIP address
$emailAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_CUSTOM", "SIP")
$emailAddress.Address = $primaryAddress
$emailAddress.IsPrimary = $true

# Add the new SIP address to the existing list
$emailAddresses.Add("ADS_PROPERTY_APPEND", $emailAddress)
$mailboxParams.EmailAddresses = $emailAddresses

# Save changes
$mailboxParams.EmailAddresses = $emailAddresses
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
avatar
Thomas Aug 10, 2023
Thank you!
Worked perfectly
Leave a comment
Loading...

Got questions?

Support Questions & Answers