Morning and happy new year : )
I noticed my script to deny pending approvals >30 days is failing currently due to the error
Approvals: You are not allowed to deny this request.
I am using this script since a while and it was working well in the past, no changes has been made so far.
https://www.adaxes.com/script-repository/approvedeny-outdated-approval-requests-s546.htm
The PowerShell script log shows
Exception calling "Deny" with "1" argument(s): "You are not allowed to deny this request." Stack trace: at <ScriptBlock>, <No file>: line 35
Line 35 is
$request.Deny($reason)
My full script
$requestExpirationDays = 30
$reason = "The request is denied because it was not processed within $requestExpirationDays days"
# 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.BindToObjectEx("Adaxes://<GUID=$guid>", $True)
# Check if we need to skip special approvals
if( $request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***" -or `
$request.DescriptionOfOperationToApprove -like "***"
) {
continue
}
# Check whether the request must be denied
$deadlineDate = $request.CreationDate.AddDays($requestExpirationDays)
if ([System.DateTime]::Now -lt $deadlineDate) {
continue
}
$request.Deny($reason)
}
My scheduled task (already re-created it for testing)
My action
