This script outputs the list of approved, denied or cancelled approval requests initiated during the number days specified in the $numDays variable. The script should be executed in Windows PowerShell on the computer where Adaxes service is installed.
PowerShell
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$daysNumber = 30 # TODO: modify me
$admNS = New-Object("Softerra.Adaxes.Adsi.AdmNamespace")
$admService = $admNS.GetServiceDirectly("localhost")
# Get approval requests
$state = 1 # Approved requests
# $state = 2 # Denied requests
# $state = 3 # Canceled requests
# Bind to the Approval Requests container
$containerPath = $admService.Backend.GetConfigurationContainerPath("ApprovalRequests")
$searcher = $admService.OpenObject($containerPath.ToString(), $NULL, $NULL, 0)
# Set search parameters
$startDateTime = ((Get-Date).AddDays(-$daysNumber)).ToFileTime()
$searcher.SearchFilter = "(&(objectCategory=adm-ApprovalRequest)(adm-ApprovalState=$state)(adm-ApprovalRequestCreationTime>=$startDateTime))"
$searcher.PageSize = 500
try
{
# Execute search
$searchResult = $searcher.ExecuteSearch()
# Iterate through the requests
foreach ($requestId in $searchResult.FetchAll())
{
$request = $admService.OpenObject($requestId.AdsPath, $NULL, $NULL, 0)
Write-Host "Date: " $request.CreationDate
Write-Host "Operation:" $request.DescriptionOfOperationToApprove
Write-Host "ProcessedBy:" $request.ProcessedBy.Get("name")
Write-Host "Requestor:" $request.Requestor.Get("name")
Write-Host
}
}
finally
{
$searchResult.Dispose()
}