In System Center 2012 R2 Configuration Manager, you perform a synchronous query for System Center 2012 R2 Configuration Manager objects by calling the SWbemServices object ExecQuery method and passing a WQL query.
A synchronous query is a query that maintains control over the process of your application for the duration of the query. A synchronous query has the potential of locking up your application for large queries or for queries over a network. Alternatively, you can run an asynchronous query that returns control to the application while the query is run. For more information, see How to Perform an Asynchronous Configuration Manager Query by Using Managed Code
|Lazy properties are not returned in synchronous queries. For more information, see How to Read Lazy Properties by Using WMI.|
To perform a synchronous query
Set up a connection to the SMS Provider. For more information, see How to Connect to an SMS Provider in Configuration Manager by Using WMI.
Using the SWbemServices object that you obtain from step one, use the ExecQuery method to get a SWbemObjectSet collection containing the query results.
Iterate through the SWbemObjectSet collection to access a SWbemObject for each object returned by the query.
The following example performs a synchronous query of all packages in Configuration Manager.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
|Visual Basic Script||Copy Code|
Sub QueryPackages(connection) On Error Resume next Dim packages Dim package ' Run the query. Set packages = _ connection.ExecQuery("Select * From SMS_Package") If Err.Number<>0 Then Wscript.Echo "Couldn't get Packages" Wscript.Quit End If For Each package In packages WScript.Echo package.Name Next If packages.Count=0 Then Wscript.Echo "No packages found" End If End Sub
This example method has the following parameters:
A valid connection to the SMS Provider.
TasksHow to Call a Configuration Manager Object Class Method by Using WMI
How to Connect to an SMS Provider in Configuration Manager by Using WMI
How 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 Read a Configuration Manager Object by Using WMI
How to Read Lazy Properties by Using WMI
ConceptsConfiguration Manager Objects Overview
How to Use Configuration Manager Objects with WMI
Configuration Manager Extended WMI Query Language
Configuration Manager Result Sets
Configuration Manager Special Queries
Configuration Manager Queries