Creating and Managing SMS Queries

You must have the appropriate permissions for the Queries security object class to create, export, or import a query. You must also have the appropriate permissions for the Queries security object class or instance to modify, delete, or view the results of the query. For more information about SMS security, see Chapter 5, "Understanding SMS Security," in the Microsoft Systems Management Server 2003 Concepts, Planning, and Deployment Guide.

On This Page

Active Directory Object Queries
Predefined Queries
Status Message Queries
Copying a Predefined Query to Create a New Query
Creating, Modifying, and Deleting a New Query
Exporting or Importing Queries

Active Directory Object Queries

Unlike Active Directory, SMS does not store Active Directory objects by distinguished name, which identifies the object and its location in a tree. Instead, SMS stores Active Directory objects by relative distinguished name, so that you can locate an object even if the exact distinguished name is unknown or if it has changed. A relative distinguished name uniquely identifies the object within its parent container.

When building queries to gather Active Directory information, query by relative distinguished name. Because you can have duplicate relative distinguished names for Active Directory objects, you might want to build your query in a way that prevents duplicate relative distinguished names from being returned by the query.

The manner in which you create queries that are based on resource properties discovered by Active Directory discovery methods differs from the way you create queries based on other discovery methods because of the way Active Directory objects are stored in the SMS site database. To obtain user information from Active Directory, you must create queries that query the Active Directory object where user accounts are contained, such as an organizational unit or distribution group. For example, when creating a query based on users' membership in a distribution group, use the User_Group_Name property of the User resource type. Specify the distribution group as <domain>\<displayed distribution group name>.

To run or update the results of a previously run query

  1. In the SMS Administrator console, navigate to Queries.

  2. Where?

    Systems Management Server > Site Database (site code - site name) >Queries

  3. Right-click the query that you want to run or update, and then click Run Query.

    -Or-

    Select the query and press F5.

    The query results appear in the console details pane.

You also can run a query and limit the number of items that the query returns.

To limit the number of items that a query returns

  1. In the SMS Administrator console, navigate to Queries.

  2. Right-click the query that you want to run or update, point to All Tasks, and then click Run Query Special.

  3. In the Run Query Special dialog box, specify a limit for the number of items you want returned.

Predefined Queries

SMS 2003 includes a set of predefined queries that you can use to accomplish common resource management tasks. For example, the Systems by Last Logged On User query locates the systems where a specified user name is the last user logged on.

Status Message Queries

In addition to the predefined queries, SMS 2003 includes a set of special-function Status Message Queries as part of the SMS Status system. The Status Message Queries can assist you in both monitoring and troubleshooting your SMS sites. For example, you might use the Queries Created, Modified, or Deleted message status query to identify changes to queries made within a specified time period.

These specialized queries are located in a different section of the SMS Administrator console. To work with Status Message Queries, navigate to Status Message Queries.

Where?

Systems Management Server > Site Database (site code - site name) >System Status >Status Message Queries

Note

  • When a site is upgraded to SMS 2003, Legacy Client Status Message Queries replace SMS 2.0 Client Status Message Queries.

For more information about Status Message Queries, see the SMS Help.

Copying a Predefined Query to Create a New Query

Instead of creating an entirely new query, you might want to modify one of the predefined queries to create a new query. If you modify the predefined queries, you lose the original query. Always make a copy of the predefined query to create your modified version from.

To copy a predefined query to create a new query

  1. In the SMS Administrator console, navigate to Queries.

  2. Right-click Queries, point to New, and then select Query.

  3. Click Browse and select an existing query.

  4. Modify the properties and give the query a unique name.

Creating, Modifying, and Deleting a New Query

To create a new query

  1. In the SMS Administrator console, navigate to Queries.

  2. Right-click Queries, point to New, and then click Query.

  3. In the Query Properties dialog box, use the General and Security tabs to specify the query properties.

  4. To create or edit the query statement properties, click Edit Query Statement. For more information about this process, see the "Creating and Editing Query Statements" section later in this chapter.

Note

  • You cannot create a new query with the same name as an existing query.

For more information about creating queries, see the SMS Help.

To modify an existing query

  1. In the SMS Administrator console, navigate to Queries.

  2. Right-click the query that you want to modify. In the Query Properties dialog box, use the General and Security tabs to change the properties that you want to modify.

To delete a query

  1. In the SMS Administrator console, navigate to Queries.

  2. Right-click the query you want to delete and click Delete.

Exporting or Importing Queries

You can use the Export Object Wizard and the Import Object Wizard to export or import SMS queries. When you export a query, the query's definitions are written to a MOF file that then can be imported.

You must have Read permission for the Queries security object class or instance to export a query. You must have Create permission for the Queries security object class to import queries.

When a query is exported as a MOF file, the query's Object ID is not written to the MOF file. This prevents an existing query from being accidentally replaced if the MOF file is imported and the Object ID of the imported query matches the Object ID of an existing query.

The Export Object Wizard cannot maintain references to other objects. If you export a query that is limited to a collection, then that reference is lost and must be reconfigured when the query is imported.

When you import queries, ensure that none of the queries have the same name as an existing query. If you do so, the data for the existing query is replaced without warning. To change the name of a query in a MOF file, you can open and edit the MOF file with any text editor.

Note

  • To import a MOF file by using the Import Object Wizard, the file must be in the Unicode file format. All MOF files that are exported by the Export Object Wizard are in the Unicode file format.

Importing multiple object classes

You can use the Export Object Wizard to export objects from only one object class at a time. MOF files that are created by using the Export Object Wizard contain only one object class. You can use the Import Object Wizard to import user-created MOF files that contain objects from multiple object classes. However, if you do not have Create permission for all object classes in a MOF file, some objects might not be imported. For example, if a MOF file contains both reports and collections, and you have Create permission only for the Reports object class, the collections are not imported.

To export queries

  1. In the SMS Administrator console, navigate to and right-click Queries.

    -Or-

    Navigate to Queries and right-click the query that you want to export.

  2. Point to All Tasks and click Export Objects.

  3. Complete the Export Object Wizard, and then click Finish.

    For more information about completing the Export Object Wizard, see the SMS Help.

To import queries

  1. In the SMS Administrator console, navigate to Site Database.

  2. Right-click Site Database, point to All Tasks, and then click Import Objects.

  3. Complete the Import Object Wizard, and then click Finish.

For more information about completing the Import Object Wizard, see the SMS Help.

Caution

  • Do not import a query with a name that is the same as the name of an existing query. If you do so, the properties of the existing query are replaced without warning. To avoid this, you can open the MOF file by using any text file application and check the object names against the name of existing objects in the SMS site database.
For More Information

Did you find this information useful? Please send your suggestions and comments about the documentation to smsdocs@microsoft.com