Script repository
The script emails a report including 10 users who approved the most requests. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.
Parameters
$to- email address of the notification recipient.$subject- the email notification subject.$reportHeader- the email notification header.$reportFooter- the email notification footer.
$to = "recipient@domain.com" # TODO: modify me
$subject = "Top 10 Approvers" # TODO: modify me
$reportHeader = "<h2><b>Top 10 Approvers</b></h2>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
function GetDisplayName($path)
{
return $Context.GetDisplayNameFromAdsPath($path)
}
# Find all approved requests.
$containerPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$searcher = $Context.BindToObject($containerPath)
$searcher.SearchFilter = "(&(objectClass=adm-ApprovalRequest)(adm-ApprovalState=1))"
$searcher.PageSize = 500
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.SetPropertiesToLoad(@("adm-ProcessedByGuid"))
try
{
$searchResult = $searcher.ExecuteSearch()
$requests = $searchResult.FetchAll()
$approverInfo = @{}
foreach ($requestId in $requests)
{
$approverGuid = [Guid]$requestId.Properties["adm-ProcessedByGuid"].Value
if ($approverInfo.ContainsKey($approverGuid))
{
$approverInfo[$approverGuid] += 1
}
else
{
$approverInfo.Add($approverGuid, 1) | Out-Null
}
}
}
finally
{
$searchResult.Dispose()
}
# Get top 10 approvers.
$result = $approverInfo.GetEnumerator() | Sort value -Descending | Select -First 10
# 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")
}
# Build report
$reportHeader += "<ol>"
foreach ($entry in $result)
{
$approverGuid = $entry.Key
$path = "Adaxes://<GUID=$approverGuid>"
# Add approver info to the report.
$approver = $Context.BindToObject($path)
$approverDisplayName = GetDisplayName $approver.AdsPath
$processedRequests = $entry.Value
$reportHeader += "<li><a href='$webInterfaceAddress`ViewObject.aspx?guid=$approverGuid'>$approverDisplayName</a>; <br/>Processed requests: $processedRequests</li>"li>"
}
$reportHeader += "</ol>"
# Send mail
$report = $reportHeader + $reportFooter
$Context.SendMail($to, $subject, $NULL, $report)
Comments 0
You must be signed in to comment.