Script Repository


Processed Approval Requests initiated during the last X days

March 01, 2019
1268

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.

Edit Remove
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()
}

Comments ( 0 )
No results found.
Leave a comment