Script Repository


Remove assistants and secretaries from Approval Requests

December 10, 2021
1247

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 )
No results found.
Leave a comment

Related Scripts