To call a SMS Provider class method, in System Center 2012 Configuration Manager, you use the ExecuteMethod method. You populate a Dictionary object with the method's parameters, and the return value is an IResultObject object that contains the result of the method call.
Note |
---|
To call a method on an object instance, use the ExecuteMethod method on the IResultObject object instance. |
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.
-
Create the input parameters as a Dictionary object.
-
Using the WqlConnectionManager object instance, call ExecuteMethod and specify the class name and input parameters.
-
Retrieve the method return value from the ReturnValue property in the returned IResultObject 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.
Copy Code | |
---|---|
public void ValidateQueryRule(WqlConnectionManager connection, string wqlQuery) { try { Dictionary<string,object> validateQueryParameters = new Dictionary<string,object>(); // Add the sql query as the WQLQuery parameter. validateQueryParameters.Add("WQLQuery",wqlQuery); // Call the method IResultObject result=connection.ExecuteMethod("SMS_CollectionRuleQuery", "ValidateQuery", validateQueryParameters); if (result["ReturnValue"].BooleanValue == true) { Console.WriteLine (wqlQuery + " is a valid query"); } else { Console.WriteLine (wqlQuery + " is not a valid query"); } } catch (SmsException ex) { Console.WriteLine("Failed to validate query rule: ",ex.Message); throw; } } |
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
Namespaces
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
The Configuration Manager exceptions that can be raised are SmsConnectionException and SmsQueryException. These can be caught together with SmsException.
See Also
Tasks
How to Connect to an SMS Provider in Configuration Manager by Using Managed CodeHow to Create a Configuration Manager Object by Using Managed Code
How to Modify a Configuration Manager Object by Using Managed Code
How to Perform an Asynchronous Configuration Manager Query by Using Managed Code
How to Perform a Synchronous Configuration Manager Query by Using Managed Code
How to Read a Configuration Manager Object by Using Managed Code
Concepts
About Configuration Manager ObjectsHow to Use Configuration Manager Objects with Managed Code