Hello,
The Scheduled Task is configured to be triggered on a Domain-DNS object, which means that it will be triggered on a domain. However, you've specified an Organizational Unit as the Activity Scope of the Scheduled Task. Organizational Units don't contain any domains, thus, the Scheduled Task is never triggered.
As far as we understand from your screenshot, you want the task to generate reports for managers located in a certain OU only. We've modified the script for you. The script will generate the report for the OU on which it is executed. In your Scheduled Task, replace the script that you currently have with the following script:
$to = "recipient@example.com" # TODO: modify me
function GetObjectDisplayName($objectDN)
{
$objectPath = New-Object -TypeName "Softerra.Adaxes.Adsi.AdsPath"`
-ArgumentList @($null, $objectDN)
return [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName(
$objectPath, "IncludeParentPath")
}
# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for Adaxes service. For details, see http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
$htmlBuilder = New-Object "System.Text.StringBuilder"
$htmlBuilder.Append("<html><head>")
$htmlBuilder.Append("<meta http-equiv=""Content-Type""`
content=""text/html charset=UTF-8""></head>")
$htmlBuilder.Append("<body>")
$htmlBuilder.Append("<p>Disabled Managers</p>")
$htmlBuilder.Append("<table width=""100%%"" border=""1"">")
$htmlBuilder.Append("<tr>")
$htmlBuilder.Append("<th>Full Name</th><th>Username</th>
<th>Parent</th><th>Direct Reports</th>")
if ($appendWebInterfaceLink)
{
$htmlBuilder.Append("<th>Link</th>")
}
$htmlBuilder.Append("</tr>")
# Find disabled managers with direct reports
$searcher = $Context.TargetObject
$searcher.PageSize = 500
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchFilter = "(&(objectCategory=user)(samAccountName=*)(userAccountControl:1.2.840.113556.1.4.803:=2)(directReports=*))"
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
try
{
$searchResult = $searcher.ExecuteSearch()
$disabledManagers = $searchResult.FetchAll()
# Add information on each manager to the report
if ($disabledManagers.Count -gt 0)
{
foreach ($manager in $disabledManagers)
{
$manager = $Context.BindToObject($manager.AdsPath)
$managerDN = New-Object "Softerra.Adaxes.Ldap.DN" $manager.Get("distinguishedName")
$parentDisplayName = GetObjectDisplayName($managerDN.Parent.ToString())
$htmlBuilder.Append("<tr>")
$htmlBuilder.AppendFormat("<td>{0}</td>", $manager.Get("name"))
$htmlBuilder.AppendFormat("<td>{0}</td>", $manager.Get("sAMAccountName"))
$htmlBuilder.AppendFormat("<td>{0}</td>", $parentDisplayName)
# Append direct reports
$htmlBuilder.Append("<td>")
foreach ($directReportDN in $manager.GetEx("directReports"))
{
$directReport = $Context.BindToObjectByDN($directReportDN)
$htmlBuilder.AppendFormat("{0} ({1})<br />", $directReport.Get("name"), $directReport.Get("sAMAccountName"))
}
$htmlBuilder.Append("</td>")
if ($appendWebInterfaceLink)
{
$htmlBuilder.AppendFormat("<td><a href='$webInterfaceAddress`ViewObject.aspx?guid={0}'>View</a></td>", [Guid]$manager.Get("objectGUID"))
}
$htmlBuilder.Append("</tr>")
}
}
$htmlBuilder.Append("</table>")
$htmlBuilder.AppendFormat("Total: {0} managers", $disabledManagers.Count.ToString())
$htmlBuilder.Append("</body></html>")
$Context.SendMail($to, "[AD Report] Disabled Managers", $NULL, $htmlBuilder.ToString())
}
finally
{
$searchResult.Dispose()
}