Wait for WorkFlow in MIM

When running sync (FIM 2010 / MIM 2016) or scripting against FIMService we sometimes have to wait for some WorkFlow to finish before we continue.
Using a small script that can be called to do the wait is a solution I use at several customers.

The example script below uses my FIMService PowerShell Module.
It takes two parameters.
The $Creator is the Creator whose request we are waiting for. The default creator is the Built-in Synchronization Account.
The $RetryInterval is the sleep time we use between checking the status of the requests still in PostProcessing.

At some customers I have also added some more logic to query for Failed requests and act upon them as well.

<#
    Script that waits for WF triggered by requests.
    Used in Schedules to get dynamic sleep time before importing results after export to FIM Service.
    Default Creator is Built-in Synchronization Account.
#>
PARAM(
    [string]$Creator = 'fb89aefa-5ea1-47f1-8890-abe7797d6497',
    [int]$RetryInterval = 30
    )

if(!(Get-Module -Name FIMServiceModule))
{
Import-Module 'D:\FIMData\FIMServiceModule.psm1' -ArgumentList 'http://idmservice.ad.konab.net:5725/resourcemanagementservice'
}

$NotDone = $true

while($NotDone)
{$Running=GetByxPath -xPath "/Request[Creator='$Creator' and RequestStatus='PostProcessing']"
    if($Running)
    {
    (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + ": WF is not done.. Waiting " + $RetryInterval + " seconds"
    Start-Sleep -Seconds $RetryInterval
    }
    else
    {
    (Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + ": WF is done. Continuing"
    $NotDone=$false
    }
}

One Reply to “Wait for WorkFlow in MIM”

  1. Pingback: Scheduling MIM with advanced options - Kent Nordström | konab.com

Leave a Reply

Your email address will not be published. Required fields are marked *