The script sends an email notification with subordinates of a user that have a specific property empty. To run the script, create a custom command, business rule or scheduled task configured for the User object type.
Parameters:
- $propertyToCheck - Specifies the LDAP name of the property whose value will be checked for the user subordinates.
- $to - Specifies the recipient's email address.
- $reportHeader - Specifies the report header.
- $reportFooter - Specifies the report footer.
PowerShell
$propertyToCheck = "employeeID" # TODO: moidfy me
# Email settings
$to = "%mail%" # TODO: modify me
$subject = "Subordinates with empty '$propertyToCheck'" # TODO: modify me
$reportHeader = "<h3><b>Subordinates with empty '$propertyToCheck'</b></h3><br/>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this E-mail, it was sent to you for notification purposes only.</i></p>" # TODO: modify me
# Get subordinates
try
{
$directReportDNs = $Context.TargetObject.GetEx("directReports")
}
catch
{
$Context.LogMessage("The user doesn't have any subordinates.", "Warning") # TODO: modify me
return
}
if ([System.String]::IsNullOrEmpty($to))
{
$Context.LogMessage("Email address is empty.", "Warning")
return
}
# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default Web Interface address is not set for Adaxes service. For details, see http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
# Check subordinates
$listItems = ""
foreach ($dn in $directReportDNs)
{
$user = $Context.BindToObjectByDN($dn)
try
{
$propertyValue = $user.Get($propertyToCheck)
}
catch
{
$propertyValue = $NULL
}
if (-not([System.String]::IsNullOrEmpty($propertyValue)))
{
continue
}
# Add user to report
$guid = [Guid]$user.Get("objectGUID")
$username = $user.Get("name")
$userLink = "<a href='$webInterfaceAddress`ViewObject.aspx?guid=$guid'>$username</a>"
$listItems += "<li>$userLink</li>"
}
if ([System.String]::IsNullOrEmpty($listItems))
{
$html = $reportHeader + "<b>All subordinates has value for property '$propertyToCheck'</b>" + $reportFooter
}
else
{
$html = $reportHeader + "<ol>" + $listItems + "</ol>" + $reportFooter
}
# Send mail
$Context.SendMail($to, $subject, $NULL, $html)