To call a SMS Provider class method, in System Center 2012 Configuration Manager, you use the SWbemServices object ExecMethod method to call methods that are defined by the class.
Note |
---|
To call a method on an object instance, call the method from
the object directly. For example, ObjectInstance.MethodName
parameters . |
To call a Configuration Manager object class method
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Using the SWbemServices you obtain in step one, call Get to get the class definition.
-
Create the input parameters as a SWbemMethodSet.
-
Using the SWbemServices object instance, call ExecuteMethod and specify the class name and input parameters.
-
Retrieve the method return value from the ReturnValue property in the returned SWbemObject object.
Example
The following example validates a collection rule query by calling the SMS_CollectionRuleQuery class ValidateQuery class method.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | Copy Code |
---|---|
Sub ValidateQueryRule(connection, wqlQuery) Dim inParams Dim outParams Dim collectionRuleClass On Error Resume Next ' Obtain the class definition object of a SMS_CollectionRuleQuery object. Set collectionRuleClass = connection.Get("SMS_CollectionRuleQuery") If Err.Number<>0 Then Wscript.Echo "Couldn't get collection rule query object" Exit Sub End If ' Set up the in parameter. Set inParams = collectionRuleClass.Methods_("ValidateQuery").InParameters.SpawnInstance_ inParams.WQLQuery = wqlQuery If Err.Number<>0 Then Wscript.Echo "Couldn't get in parameters object" Exit Sub End If ' Call the method. Set outParams = _ connection.ExecMethod( "SMS_CollectionRuleQuery", "ValidateQuery", inParams) If Err.Number<>0 Then Wscript.Echo "Couldn't run method" Exit Sub End If If outParams.ReturnValue = True Then Wscript.Echo "Valid query" Else WScript.Echo "Not a valid query" End If End Sub |
This example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection |
|
A valid connection to the SMS Provider. |
wqlQuery |
|
A WQL query string. For this example, |
Compiling the Code
See Also
Tasks
How to Connect to an SMS Provider in Configuration Manager by Using WMIHow to Create a Configuration Manager Object by Using WMI
How to Delete a Configuration Manager Object by Using WMI
How to Modify a Configuration Manager Object by Using WMI
How to Perform an Asynchronous Configuration Manager Query by Using WMI
How to Perform a Synchronous Configuration Manager Query by Using WMI
How to Read a Configuration Manager Object by Using WMI
How to Read Lazy Properties by Using WMI
Concepts
Configuration Manager Objects OverviewHow to Use Configuration Manager Objects with WMI