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

Remove assistants and secretaries from Approval Requests

December 10, 2021 Views: 1827

The script removes an assistant or secretary of a user from lists of approvers of pending approval requests the user can approve.

To use the script, you can create a custom command that runs the script and run it on the user or users assistant or secretary you want to remove. In order to add the script to your command, use the Run a program or PowerShell script action.

Parameter:

  • $approverDNProperty - Specifies the property that contains the approver. Use assistant or secretary.
See Also: Delegate approvals to assistants and secretaries.
Edit Remove
PowerShell
$approverDNProperty = "assistant" # TODO: modify me

# Get the approver DN
try
{
    $approverDN = $Context.TargetObject.Get($approverDNProperty)
}
catch
{
    $Context.LogMessage("Property '$approverDNProperty' is empty", "Warning") # TODO: modify me
    return
}

# Get all requests awaiting for approval by user
$requests = $Context.TargetObject.GetApprovals("ADM_APPROVALSTATE_PENDING")
if ($requests.Length -eq 0)
{
    return # No requests awaiting for approval by the user
}

# Bind to the approver
$approver = $Context.BindToObjectByDN($approverDN)

# Remove the approver from each request
foreach ($requestID in $requests)
{
    # Bind to the request
    $requestGuid = [Guid]$requestID
    $path = "Adaxes://<GUID=$requestGuid>"
    $request = $Context.BindToObject($path)
    
    # Get approvers info
    $approversInfo = $request.GetApproversInfo()
    $approverTrustees = $approversInfo.ApproverTrustees
    if (-not($approverTrustees.IsApprover($approver)))
    {
        continue
    }
    
    # Remove the approver
    $approverTrustees.Remove($approver)
    
    # Update the approvers list
    $request.SetApproversInfo($approversInfo)
    $request.SetInfo()
}

Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers