Microsoft Identity Integration Server 2003 Developer Reference |
The following Visual Basic Scripting Edition (VBScript) example shows you how to check the results of a management agent run prior to importing the objects in the metaverse. This example assumes that the Fabrikam HR MA management agent has the following run profiles:
The example first 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, then the example runs the management agent with a delta synchronization run profile to import the objects into the metaverse.
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
Preventing Damage to the Metaverse and Connected Data Source, Example: Preventing Connected Data Source Damage, Enabling Security in Scripts