Script repository

Process pending approval requests created more than X days ago

Updated on: Jan 18, 2026, Views: 4272

Approval requests

The scripts approve/deny pending approval requests which were created more than X days ago. To execute the script, create a scheduled task configured for the Domain object type and add a managed domain to the Activity Scope of the task. The domain will only be used to trigger execution of the scheduled task.

Script 1: Deny outdated requests

Parameters

  • $requestExpirationDays – the number of days an approval request needs to remain pending to become outdated.
  • $reason – the reason for requests denial.
$requestExpirationDays = 30 # TODO: modify me
$reason = "The request is denied because it was not processed within $requestExpirationDays days" # TODO: modify me

# Bind to the 'Approval Requests' container.
$approvalRequestsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$container = $Context.BindToObject($approvalRequestsPath)

# Get all pending approval requests.
$requestGuidsInBytes = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")

# Iterate through the requests.
foreach ($guidInBytes in $requestGuidsInBytes)
{
    # Bind to the approval request.
    $guid = [Guid]$guidInBytes
    $request = $Context.BindToObject("Adaxes://<GUID=$guid>")
    
    # Check whether the request must be denied.
    $deadlineDate = $request.CreationDate.AddDays($requestExpirationDays)
    if ([System.DateTime]::Now -lt $deadlineDate)
    {
        continue
    }

    $request.Deny($reason)
}

Script 2: Approve outdated requests

In the script, the $requestExpirationDays variable specifies the number of days an approval request needs to remain pending to become outdated.

$requestExpirationDays = 30 # TODO: modify me

# Bind to the 'Approval Requests' container.
$approvalRequestsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$container = $Context.BindToObject($approvalRequestsPath)

# Get all pending approval requests.
$requestGuidsInBytes = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")

# Iterate through the requests.
foreach ($guidInBytes in $requestGuidsInBytes)
{
    # Bind to the approval request.
    $guid = [Guid]$guidInBytes
    $request = $Context.BindToObject("Adaxes://<GUID=$guid>")
    
    # Check whether the request must be approved.
    $deadlineDate = $request.CreationDate.AddDays($requestExpirationDays)
    if ([System.DateTime]::Now -lt $deadlineDate)
    {
        continue
    }

    $request.Approve()
}

Comments 3

You must be signed in to comment.

  • Gareth

    Gareth

    Is there a way I can tie this script to just one initiator? I'd like to run this but only from approval requests that have been initated by a specific scheduled task.

    • Support

      Support

      Yes, it is possible. Please, find the updated scripts below. In the scripts, the $scheduledTaskDN variable was added. It specifies the distinguished name (DN) of the scheduled task that initiated requests which must be processed. For information on how to get an object DN, have a look at the following SDK article: https://www.adaxes.com/sdk/HowDoI.GetDnOfObject.

      Deny outdated approval requests

      $requestExpirationDays = 30 # TODO: modify me
      $scheduledTaskDN = "CN=MyTask,CN=Scheduled Tasks,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
      $reason = "The request is denied because it was not processed within $requestExpirationDays days" # TODO: modify me
      
      $task = $Context.BindToObjectByDN($scheduledTaskDN)
      $taskGuid = [Guid]$task.Get("objectGuid")
      
      # Bind to the 'Approval Requests' container
      $approvalRequestsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
      $container = $Context.BindToObject($approvalRequestsPath)
      
      # Get all pending approval requests
      $requestGuidsInBytes = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
      
      # Iterate through the requests
      foreach ($guidInBytes in $requestGuidsInBytes)
      {
          # Bind to the approval request
          $guid = [Guid]$guidInBytes
          $request = $Context.BindToObject("Adaxes://<GUID=$guid>")
          
          # Check whether the request must be denied
          $deadlineDate = $request.CreationDate.AddDays($requestExpirationDays)
          $requestorGuid = [Guid]$request.Get("adm-ApprovalRequestorGuid")
          
          if ([System.DateTime]::Now -lt $deadlineDate -or ($requestorGuid -ne $taskGuid))
          {
              continue
          }
      
          $request.Deny($reason)
      }
      

      Approve outdated approval requests

      $requestExpirationDays = 30 # TODO: modify me
      $scheduledTaskDN = "CN=MyTask,CN=Scheduled Tasks,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me
      
      $task = $Context.BindToObjectByDN($scheduledTaskDN)
      $taskGuid = [Guid]$task.Get("objectGuid")
      
      # Bind to the 'Approval Requests' container
      $approvalRequestsPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
      $container = $Context.BindToObject($approvalRequestsPath)
      
      # Get all pending approval requests
      $requestGuidsInBytes = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
      
      # Iterate through the requests
      foreach ($guidInBytes in $requestGuidsInBytes)
      {
          # Bind to the approval request
          $guid = [Guid]$guidInBytes
          $request = $Context.BindToObject("Adaxes://<GUID=$guid>")
          
          # Check whether the request must be approved
          $deadlineDate = $request.CreationDate.AddDays($requestExpirationDays)
          $requestorGuid = [Guid]$request.Get("adm-ApprovalRequestorGuid")
          
          if ([System.DateTime]::Now -lt $deadlineDate -or ($requestorGuid -ne $taskGuid))
          {
              continue
          }
      
          $request.Approve()
      }
      
      • Gareth

        Gareth

        Works perfect, thank you!

Got questions?

Support Questions & Answers

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.