System Center Configuration Manager 2007 : Creating Queries (part 1) - Objects, Classes, and Attributes
Creating queries is a safe way to obtain data from ConfigMgr. When you use the Query Builder, the class joins are automatically created, thus reducing the risk of an improper join that could be resource intensive. The following sections provide additional insight into the query language, as well as the types of objects you can query.
The Query Language
ConfigMgr queries use the WMI Query Language (WQL) to gather information from the site database. In this way, queries differ from Configuration Manager reports , which use standard SQL syntax to access database information. ConfigMgr uses WMI for much more than just ConfigMgr queries. The ConfigMgr Software Development Kit (SDK) is a great place to learn more about WMI and WQL as well as Configuration Manager’s use of these technologies.
Objects, Classes, and Attributes
Prior to building queries, let’s discuss the terminology and the objects you will use. When selecting data in a query, you select an object type, one or more attribute classes, and one or more attributes. These terms are defined in the following list:
Object type— A set of attributes that represents a ConfigMgr database object, such as a client, package, or advertisement. Table 1 shows the object types available for queries.
Table 1. Object Types Available for ConfigMgr Queries
Object Type Description Advertisement A single attribute class that contains the data in a ConfigMgr advertisement, such as advertisement name, advertisement ID, package ID, package name, and more. This class will not tell you the advertisement status, but describes the properties of an advertisement. Software Metering Rules A single attribute class containing the data in a ConfigMgr software metering rule, such as rule name, filename to meter, and whether the rule is enabled. This class will not tell you metering rule summary information, but will tell you the properties of the rule. Package A single attribute class that contains the data in a ConfigMgr package, such as package name, package ID, source path, and more. Program A single attribute class containing the data in a ConfigMgr program, such as program name, package ID (to associate the program with a package), dependent program package information, and more. Site A single attribute class that contains the data in a ConfigMgr site, such as server name, build number, and site version. System Resource Many attribute classes containing the data for a computer system, such as discovery information, hardware and software information, and so on, are System Resource objects. User Resource A single attribute class that contains the discovery data for user objects, such as user name, full user name, and user Organizational Unit (OU). Use this class when building queries that can be imported into collections for user-targeted advertisements. User Group Resource A single attribute class containing the discovery data for user group objects, such as user group name and domain. Use this class when building queries that can be imported into collections for user group–targeted advertisements. Attribute class— A container object that groups related attributes. For example, the Processor attribute class contains attributes such as Device ID, Manufacturer, Resource ID, and more. You can control many of the attributes in the attribute class by modifying the attributes collected in inventory by modifying the SMS_Def.mof file. Most attributes you will use in ConfigMgr queries are members of the System Resource Object type, because all hardware and software inventory information is a member of this object type. If later you decide to build a web report (which uses SQL instead of WQL), you will find a SQL view with a similar name. As an example, the Computer System attribute class in WQL has a corresponding SQL view named v_GS_COMPUTER_SYSTEM.
Attribute— The specific property that the query searches in criteria and/or displays for query results.
Figure 1 provides an example of object types and their relationships discussed in this section. It shows the selected object type System Resource. Within the System Resource object type, three attribute classes (Processor, Operating System, and Add/Remove Programs) are selected. The lines between each object type represent the joins that are required between classes. Here is the WQL equivalent of Figure 1:
select SMS_G_System_PROCESSOR.MaxClockSpeed, SMS_G_System_PROCESSOR.Name,
SMS_G_System_OPERATING_SYSTEM.OSLanguage,
SMS_G_System_OPERATING_SYSTEM.Version,
SMS_G_System_ADD_REMOVE_PROGRAMS.Publisher from SMS_R_System inner join
SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceId =
SMS_R_System.ResourceId inner join SMS_G_System_OPERATING_SYSTEM on
SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId inner join
SMS_G_System_ADD_REMOVE_PROGRAMS on
SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceId = SMS_R_System.ResourceId
Figure 1. Example of Query object types, attribute classes, and attributes
As you can see from this code, WQL looks very similar to SQL. You will also notice that no criterion is specified (the query does not contain a WHERE clause). This particular example did not specify criteria, which is another feature of ConfigMgr queries—you may want to see all the data on occasion. You will learn in the next section how you can easily create a WQL query with criterion.