We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Processed Approval Requests initiated during the last X days

February 18, 2021 Views: 2629

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers