No problem.
$Hours = 24 # TODO: must depend on the schedule of the task
$admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$admService = $admNS.GetServiceDirectly("localhost")
function SendNotification($approval)
{
$to = "%mail%"
if ([System.String]::IsNullOrEmpty($to))
{
$Context.LogMessage("Email address is empty!", "Error")
return
}
$subject = "My Subject"
$bodyText = $NULL
$requestorName = $approval.Requestor.Get("name")
$deniedBy = $approval.ProcessedBy.Get("name")
$operation = $approval.DescriptionOfOperationToApprove
$reason = $approval.DenialOrCancelingReason
$bodyHtml = @"
Requestor: $requestorName<br />
Denied by: $deniedBy<br />
Reason: $reason<br />
Operation: $operation<br />
"@
$Context.SendMail($to, $subject, $bodyText, $bodyHtml)
}
# Bind to the Approval Requests container
$approvalsPath = $admService.Backend.GetConfigurationContainerPath("ApprovalRequests")
$aprovalsContainer = $admService.OpenObject($approvalsPath.ToString(), $NULL, $NULL, 0)
# Get all denied approval requests
$aprovals = $aprovalsContainer.GetApprovalRequests("ADM_APPROVALSTATE_DENIED")
foreach ($requestID in $aprovals)
{
# Bind to the approval request
$guid = New-Object "System.Guid" (,$requestID)
$guid = $guid.ToString("B")
$approvalsPath = "Adaxes://<GUID=$guid>"
$approval = $admService.OpenObject($approvalsPath, $NULL, $NULL, 0)
# Check whether the request was modified during the last N hours
$modificationDate = $approval.Get("whenChanged");
if ([System.DateTime]::Now -gt $modificationDate.AddHours($Hours))
{
continue
}
SendNotification($approval)
}
- Open the PowerShell script in a text editor and customize it for your needs (2012.1 will introduce an embedded PowerShell script editor).
- Launch Adaxes Administration Console.
- Run the Scheduled Task Creation wizard.
- On the 3rd step of the wizard select the User object type.
- On the 4th step, click Add Action.
- Select the Run a program of PowerShell script action.
- Paste the script to the Script edit box, click OK, and then click Next.
- On the 5th step of the wizard, click Add.
- In the dialog that opens select the User object type in the Object Types drop-down dialog.
- In the list of available objects, select the users you want to receive email notifications.
- Click OK and then click Finish.
That's it :) Little bit tricky, but works.