Script repository
The script updates the SIP address with the primary SMTP address. All existing SIP addresses will be removed. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.
# Get Exchange properties.
$mailboxParams = $Context.TargetObject.GetMailParameters()
$emailAddresses = $mailboxParams.EmailAddresses
# Remove 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")
Comments 7
You must be signed in to comment.
Thomas
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.
Support
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?
Thomas
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
Support
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?
Thomas
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!
Support
Hello Thomas,
Thank you for the confirmation. Here is the script.
Thomas
Thank you!
Worked perfectly