I belive we may have opened a ticket for this question in the past but I can't find the answer.
We have a need to delay changing user attributes until their transfer/promotion date.
So we have a Custom Command called Promote/Transfer. It takes in several parameters (manager, title, department)
We set the transfer/promotion date in adm-customattributedate2
We have a scheduled task that runs the following powershell hourly.
# Get all pending Approval Requests
$containerPath = $Context.GetWellKnownContainerPath("ApprovalRequests")
$container = $Context.BindToObject($containerPath)
$requests = $container.GetApprovalRequests("ADM_APPROVALSTATE_PENDING")
foreach ($requestID in $requests)
{
# Bind to the Approval Request
$guid = [Guid]$requestID
$request = $Context.BindToObjectEx("Adaxes://<GUID=$guid>", $True)
$approversInfo = $request.GetApproversInfo()
if (-not ($approversInfo.IsApproverEx($Context.Initiator.UserAdsObject, $request.Requestor, $request.TargetObject)))
{
continue # The Scheduled Task is not an approver
}
# Get date when modifications are due
$operation = $request.DescriptionOfOperationToApprove
$result = $operation | Select-String -Pattern "(?<=\{.{8}-.{4}-.{4}-.{4}-.{12}\}\s)\d{2}\/\d{2}\/\d{4}(?=\s\{.{8}-.{4}-.{4}-.{4}-.{12}\})"
if ($result -eq $NULL)
{
$Context.LogMessage("Cannot find a date when to execute the following operation: '$operation'.", "Warning")
continue
}
try
{
$date = [Datetime]::ParseExact($result.Matches[0].Value, "dd/MM/yyyy", $NULL)
}
catch
{
$Context.LogMessage("Cannot convert a date when to execute the following operation: '$operation'.", "Warning")
continue
}
if ($date -gt [System.Datetime]::UtcNow)
{
continue
}
# Approve the request
$request.Approve()
}
Somehow someone changed something and now its not working anymore. I can't for the life of me find the original article/ticket that this powershell came from, but it had the instructions we needed to delay modifying a user's manager, title, and department until the scheduled date.
Any help would be much much appreciated. Thanks!