This script e-mails a report on approval requests approved during a predefined number of days.
To generate such a report upon request, you can create a custom command that runs the script. To schedule the reports, you need to create a scheduled task configured for the Domain object type and run it against any of your AD domains.
To add the script to a custom command or scheduled task, use the Run a program or PowerShell script action.
Parameters:
- $numDays - Specifies the number of days to include in the report.
- $to - Specifies email addresses of the recipient(s) of the report.
- $subject - Specifies the email message subject.
- $reportHeader - Specifies the email message header.
- $reportFooter - Specifies the email message footer.
PowerShell
$numDays = 7 # TODO: modify me
$to = "recipient@example.com" # TODO: modify me
$subject = "Requests approved during the last $numDays days" # TODO: modify me
$reportHeader = "<b>Approved operations:</b><br/><br/>" # 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
# Bind to the Approval Requests container
$approvalsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$aprovalsContainer = $Context.BindToObject($approvalsPath)
# Get approved Approval Requests
$requests = $aprovalsContainer.GetApprovalRequests("ADM_APPROVALSTATE_APPROVED")
# Get default web interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for Adaxes service.", "Warning") # TODO: Modify me
}
$sendMail = $False
$modificationDate = (Get-Date).AddDays(-$numDays)
$approvedTasks = "<ol>"
# Find recently modified requests
foreach ($requestID in $requests)
{
$guid = New-Object "System.Guid" (,$requestID)
$guid = $guid.ToString("B")
$requestPath = "Adaxes://<GUID=$guid>"
$request = $Context.BindToObject($requestPath)
$requestModificationDate = ($request.Get("whenChanged")).ToLocalTime()
if ($requestModificationDate -lt $modificationDate)
{
continue # Approved earlier
}
# Add requests to the message
$requestOperation = $request.DescriptionOfOperationToApprove
$processedBy = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($request.ProcessedBy, 'IncludeParentPath')
$approvedTasks += "<li>Operation: $requestOperation<br/> Processed By: $processedBy<br/> Date: $requestModificationDate<br/><a href='$webInterfaceAddress`#/Browse/$guid'>Details</a></li>"
$sendMail = $True
}
$approvedTasks += "</ol>"
if (-not($sendMail))
{
$Context.LogMessage("No requests matching the criteria.", "Information") # TODO: Modify me
return
}
# Build report
$report = $reportHeader + $approvedTasks + $reportFooter
# Send mail
$Context.SendMail($to, $subject, $NULL, $report)