Script Repository


Process pending approval requests created more than X days ago

April 06, 2020
164

The scripts process outdated approval requests that were not approved, denied or cancelled within a predefined time frame. To run the script, create a Scheduled Task configured for the Domain-DNS object type.

Deny outdated approval requests

Parameters:

  • $requestExpirationDays – specifies the number of days an approval request needs to remain pending to become outdated;
  • $reason – specifies a reason for the requests denial.
Edit Remove
PowerShell
$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)
}

Approving outdated approval requests

Parameter:

  • $requestExpirationDays – specifies the number of days an approval request needs to remain pending to become outdated.
Edit Remove
PowerShell
$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 ( 0 )
No results found.
Leave a comment