Hello everyone,
I've received a task to send a report of pending and denied approval requests of a specific task to an email of one of our managers.
Since I do not want the mail to become too long with just CN's I'd like to format it in a html table.
- The first column should contain the CN's of all the Users with a pending approval request.
- The second column should contain the CN's of the users who denied the request.
- The third one should contain the date/time when the users denied the request
I am at the point where i understand where the problem is, but I do not have the knowledge to make it work.
The script first adds in the pending users and only afterwards he adds the declined.
I would be more then glad to learn new approaches or other solutions to such an task.
Here a screenshot how it looks atm:
This is how far i came.
Import-Module Adaxes
$to = #Insert Email Here
$subject = "Montly SystemUpToDate Report"
$reportHeader = @"
<h3><b>System Up To Date Report</b></h3><br data-tomark-pass />
<table border="1">
<tr>
<th>Pending</th>
<th>Denied</th>
<th>Date of Decline</th>
</tr>
"@
$reportFooter = @"
</table><br data-tomark-pass />
<p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>
"@
$numDays = 14
# Bind to the Approval Requests container
$approvalsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$aprovalsContainer = $Context.BindToObject($approvalsPath)
# Get pending Approval Requests
$pendingrequests = $aprovalsContainer.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
# Get declined Approval Requests
$deniedrequests = $aprovalsContainer.GetApprovalRequests("ADM_APPROVALSTATE_DENIED")
$modificationDate = (Get-Date).AddDays(-$numDays)
# Find pending requests in the last 15 days
foreach ($requestID in $pendingrequests)
{
$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 # within in time-frame
}
$requestOperation = $request.DescriptionOfOperationToApprove
if ($requestOperation -match "Is system up to date")
{
# Add requests to the message
#$pendingTasks += "<li>Operation: $requestOperation<br data-tomark-pass /> Date: $requestModificationDate<br data-tomark-pass />"
$TargetObjectPending = $request.TargetObject.Name
$reportHeader += "<tr><td>" + $TargetObjectPending + "</td>"
}
}
# Find denied requests in the last 15 days
foreach ($requestID in $deniedrequests)
{
$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 in time-frame
}
$requestOperation = $request.DescriptionOfOperationToApprove
if ($requestOperation -match "Is system up to date")
{
# Add requests to the message
# $deniedTasks += "<li>Operation: $requestOperation<br data-tomark-pass /> Date: $requestModificationDate<br data-tomark-pass />"
$TargetObjectDenied = $request.TargetObject.Name
$reportHeader += "<tr><td></td><td>" + $TargetObjectDenied + "</td><td>" + $requestModificationDate + "</td>"
}
}
#Build report
$report = $reportHeader + $reportFooter
# Send Mail
$Context.SendMail($to, $subject, $NULL, $report)