The script sends an SMS message to all users and contacts that are members of a group and of the first level nested groups. To execute the script, create a custom command, business rule or scheduled task configured for the Group object type.
Parameters:
- $mobilePhonePropertyName - Specifies the LDAP name of the property used to store mobile phones. Should be the same as the property specified in SMS settings.
- $smsText - Specifies the text of the SMS message.
PowerShell
$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)
}
}
}
}