Script repository

Send mail notification to group members

Updated on: Jan 18, 2026, Views: 5774

Miscellaneous

The script sends an email notification to members of an AD group. To execute the script, create a business rule, custom command or scheduled task configured for the Group object type.

Parameters

  • $subject - the email notification subject.
  • $messageText - the email notification text.
$subject = "Notification to %name% members" # TODO: modify me
$messageText = @"
Attention to all %name% members!

This is a notification from your support team.
"@ # TODO: modify me

try
{
    $memberGuidsInByte = $Context.TargetObject.GetEx("adm-MembersGuid")
}
catch
{
    return
}

$toAddresses = @()
foreach($memberGuidInByte in $memberGuidsInByte)
{
    $memberGuid = [guid]$memberGuidInByte
    $groupMember = $Context.BindToObject("Adaxes://<GUID=$memberGuid>")

    if($groupMember.Class -ieq "group")
    {
        continue
    }
    
    try
    {
        $mail = $groupMember.Get("mail")
    }
    catch
    {
        continue
    }
    
    $toAddresses += "$mail"
}

if ($toAddresses.Length -gt 0)
{
    $toAddressesString = [System.String]::Join(",", $toAddresses)
    $Context.SendMail($toAddressesString, $subject, $messageText, $NULL)
}

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.