Script Repository


Notify manager about adding user to group

February 23, 2021
1993

The script notifies a user manager about adding the user to a group. To use the script with Adaxes, create a business rule that runs it after adding a member to a group. To add the script to your rule, use the Run a program or PowerShell script action.

Parameters:

  • $subject - Specifies a template for the email notification subject.
  • $message - Specifies a template for the email notification message.
    You can use value references (e.g. the %name%, %adm-ParentName%) in the message and subject templates. Value references will be replaced with corresponding property values of the group. The {0} placeholder will be replaced with the name of the added user.
Edit Remove
PowerShell
$subject = "User {0} added to group '%name%'" # TODO: modify me
$message = "User {0} added to group '%name%'" # TODO: modify me

# Bind to member
$member = $Context.BindToObject("Adaxes://%member%")

if ($member.Class -ne "user")
{
    return
}

# Get manager
try
{
    $managerDN = $member.Get("manager")
}
catch
{
    return # Manager not specified
}

# Get manager mail
$manager = $Context.BindToObjectByDN($managerDN)
try
{
    $managerMail = $manager.Get("mail")
}
catch
{
    $managerName = $manager.Get("name")
    $Context.LogMessage("Could not notify the user's manager because the manager ('$managerName') does not have an e-mail address", "Warning") # TODO: modify me
    return
}

# Send notification
$memberName = $member.Get("name")
$subject = [System.String]::Format($subject, $memberName)
$message = [System.String]::Format($message, $memberName)
$Context.SendMail($managerMail, $subject, $message, $NULL)

Comments ( 0 )
No results found.
Leave a comment

Related Scripts