Script repository

Send SMS to group members

Updated on: Jan 18, 2026, Views: 5340

Miscellaneous

The script sends an SMS message to all users and contacts that are members of the target group and of the first level nested groups. To execute the script, create a business rule, custom command or scheduled task configured for the Group object type.

Parameters

  • $mobilePhonePropertyName - the name of the property used to store mobile phones. Should be the same as the property specified in SMS settings.
  • $smsText - the text of the SMS to send.
$mobilePhonePropertyName = "mobile" # TODO: modify me
$smsText = "my text"  # TODO: modify me

# Get group members.
try
{
    $memberGuidsBytes = $Context.TargetObject.GetEx("adm-DirectMembersGuid")
}
catch
{
    $Context.LogMessage("The group has no members.", "Information")
}

$alreadyProcessedGuids = New-Object System.Collections.Generic.HashSet[System.Guid]
foreach ($guidBytes in $memberGuidsBytes)
{
    $guid = [Guid]$guidBytes
    $member = $Context.BindToObject("Adaxes://<GUID=$guid>")
    
    if(($member.Class -eq "user") -or ($member.Class -eq "contact"))
    {
        # Check if mobile phone is specified.
        try
        {
            $mobileNumber = $member.Get($mobilePhonePropertyName)
        }
        catch
        {
            continue
        }
        
        [void]$alreadyProcessedGuids.Add($guid)
        $member.SendSMS($smsText, $False)
    }
    elseif($member.Class -eq "group")
    {
        # Get group members.
        try
        {
            $nestedMemberGuidsBytes = $member.GetEx("adm-DirectMembersGuid")
        }
        catch
        {
            continue
        }
        
        foreach ($nestedMemberGuidBytes in $nestedMemberGuidsBytes)
        {
            $guid = [Guid]$nestedMemberGuidBytes
            if ($alreadyProcessedGuids.Contains($guid))
            {
                continue
            }
            
            $nestedMember = $Context.BindToObject("Adaxes://<GUID=$guid>")
            if(($nestedMember.Class -eq "user") -or ($nestedMember.Class -eq "contact"))
            {
                # Check if mobile phone is specified.
                try
                {
                    $nestedMobileNumber = $nestedMember.Get($mobilePhonePropertyName)
                }
                catch
                {
                    continue
                }
                $nestedMember.SendSMS($smsText, $False)
            }
        }
    }
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.