Example: Specifying Management Agents from a Command Line
You can create a script that can run any management agent by using named arguments.
The named arguments are used to specify the management agent and run profile to run. You can then use a command file to call this script and pass the name of the management agent and run profile you would like to run. This script also returns a value that you can use to determine if you want to run another management agent or stop processing.
The following example shows how to use Visual Basic Scripting Edition (VBScript) to create a script that uses named arguments:
Option Explicit
On Error Resume Next
Const PktPrivacy = 6 ' Authentication Level
Dim ErrorLevel ' Return code
Dim Arguments ' Argument object
Dim ManagementAgentName ' String for management agent
Dim RunProfileName ' String for run profile
Dim Service ' Service object
Dim ManagementAgent ' Management agent object
Dim Status ' String for status
ErrorLevel = 1
Set Arguments = WScript.Arguments.Named
ManagementAgentName = Arguments.Item("MA")
RunProfileName = Arguments.Item("RunProfile")
Set Service = GetObject("winmgmts:{authenticationLevel=PktPrivacy}!root\MicrosoftIdentityIntegrationServer")
Set ManagementAgent = Service.Get("MIIS_ManagementAgent.Name='" & ManagementAgentName & "'")
Status = ManagementAgent.Execute(RunProfileName)
WScript.Echo ManagementAgentName & " " & RunProfileName & " Result: " & Status
If Status = "success" then
ErrorLevel = 0
End If
Sub ErrorHandler (ErrorMessage)
WScript.Echo ErrorMessage
WScript.Quit(1)
End Sub
The syntax to use is: "/MA:<Management Agent Name> /RunProfile:<Run Profile Name>"
For arguments that contain spaces, enclose the arguments with straight quotation marks (" "). Include a space between arguments.
To use this script to run the Fabrikam HR MA management agent with a full import run profile, save this script to a file called RunMA.vbs, and then type the following command-line command: RunMA /MA:"Fabrikam HR MA" /RunProfile:"Full Import".
See Also
Example: Running a Management Agent With a Specified Run Profile
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