The following Microsoft Visual Basic Scripting Edition (VBScript) example shows you how to check the results of a management agent run before you import the objects in the Forefront Identity Manager Synchronization Service (FIM Synchronization Service) database (metaverse). This example assumes that the Fabrikam HR MA management agent has the following run profiles:
- A run profile with a step to stage a full
import.
- A run profile with a step to perform a delta
synchronization.
The example uses a ratio to limit the number of object deletions. The number of object deletions must be less than 20 percent of the total number of connector space objects.
First, the example runs the management agent with a full import (stage only) run profile step and then checks the number of objects to be deleted from the metaverse. If the number of objects to be deleted from the metaverse is less than 20 percent of the objects in the connector space, the example runs the management agent with a delta synchronization run profile to import the objects into the metaverse.
Visual Basic Script | ![]() |
---|---|
Option Explicit On Error Resume Next Const PktPrivacy = 6 ' Authentication level Dim ErrorLevel ' Return code Dim Service ' Service object Dim ManagementAgent ' Management agent Dim TotalCSObjects ' Total connector space objects Dim ImportDelete ' Import Object Deletes Dim DeleteRatio ' Delete ratio Dim AcceptRatio ' Acceptable delete ratio Dim Status ' Status string ErrorLevel = 1 Set Service = GetObject("winmgmts:{authenticationLevel=PktPrivacy}!root\MicrosoftIdentityIntegrationServer") Set ManagementAgent = Service.Get("MIIS_ManagementAgent.Name='Fabrikam HR MA'") Status = ManagementAgent.Execute("Full Import") If Status = "success" Then WScript.Echo "Management Agent Run successful. Checking delete ratio." TotalCSObjects = Clng(ManagementAgent.NumCSObjects) ImportDelete = Clng(ManagementAgent.NumImportDelete) ' Calculate the delete ratio. If (ManagementAgent.NumCSObjects > 0) Then DeleteRatio = ImportDelete / TotalCSObjects * 100 Else DeleteRatio = 0 End If ' Display the delete ratio. WScript.echo "Delete Ratio: " & DeleteRatio ' In this example, the maximum acceptable delete ratio is 20 percent. AcceptRatio = 20 ' Display an error message if the delete ratio is greater than the ' acceptable amount. If DeleteRatio >= AcceptRatio Then WScript.Echo "ATTENTION: Ratio is hit. Setting errorlevel to 2" ErrorLevel = 2 Else Status = ManagementAgent.Execute("Delta Synchronization") WScript.Echo "Synchronization run result: " & Status If Status = "success" then ErrorLevel = 0 End If Else WScript.Echo "Management Agent Run failed with " & Status End If Sub ErrorHandler (ErrorMessage) WScript.Echo ErrorMessage WScript.Quit(1) End Sub |