Example: Running a Management Agent with a Specified Run Profile
While you can run a management agent from Identity Manager, the WMI Provider enables you to also run a management agent from a script. The advantages of running a management agent from a script are:
- By running a script at a specified time using the Scheduled Tasks feature of Windows Server 2003, you can minimize the impact on your infrastructure.
- You can write one script that accepts named arguments to run any management agent. For more information, see Example: Specifying Management Agents From a Command Line.
- You can sequentially run several management agents through a command file that runs a management agent only if the previous management agent run was successful. For more information, see Example: Running Several Management Agents from a Command File.
The following Visual Basic Scripting Edition (VBScript) example shows how to create a script that runs a management agent with a specified run profile. The script runs the Fabrikam HR MA management agent with a full import run profile and then returns a value. You can use this return value to determine if you can run other scripts.
Option Explicit
On Error Resume Next
Const PktPrivacy = 6 ' Authentication Level
Dim Service ' Connection object
Dim ManagementAgent ' Management agent object
Dim Status ' String for the status
Dim ErrorLevel ' Return code
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
ErrorLevel = 0
End if
WScript.Echo "Management Agent Run Result: " & Status
Sub ErrorHandler (ErrorMessage)
WScript.Echo ErrorMessage
WScript.Quit(1)
End Sub
See Also
Example: Specifying Management Agents From a Command Line
Example: Running Several Management Agents from a Command File
Enabling Security in Scripts
Send comments about this topic to Microsoft
Build date: 2/16/2009