Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

System Center Configuration Manager 2007 : Configuration Manager Queries - Advanced Queries

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/15/2011 6:06:02 PM
A favorite feature of the Query Builder is that it automatically creates the joins for you. As an example, say you want a list of all computers and the total amount of physical memory. To make things a little more complex, your boss also wants this listing to display the Active Directory Site Name, as well as a date/time stamp of when the ConfigMgr client inventoried the information. Using the Query Builder, you simply select the classes and properties you want to display (this example will use the classes of System Resource, Memory, and Workstation Status) and then run the report. The Query Builder creates all the joins for you. To see the detail, simply click the Show Query Language button after you write your query. To using the Query Builder, you can write the query statements yourself. Using WQL, you specify the WMI object classes and attributes the query will use to search the ConfigMgr site database. As an example, perhaps you want to display all systems that have reported hardware inventory in the past 30 days. There is no native way to do this using the Query Builder. Luckily, ConfigMgr supports Extended WMI Query Language, which allows you to use the following functions:
  • GetDate()— This function returns the current date and time on the system. The data is returned in date-time format (for example, 12:56 AM 12/02/2009).

  • DateDiff()— This function returns the difference between two date-time values in the increment you specify (for example, minute, hour, day). The DateParts listed in Table 1 are supported when using DateDiff in a WHERE clause in SMS WQL. Here’s the proper syntax for DateDiff:

    DateDiff ( DatePart, StartDate, EndDate )
    • DatePart is the part of the date you want to calculate (minute, day, month, and so on).

    • StartDate is the begin date.

    • EndDate is the ending date.

    Table 1. DateParts and Abbreviations
    DatePartAbbreviation
    Yearyy
    Monthmm
    Daydd
    Hourhh
    Minutemi
    Secondss

  • DateAdd()— Returns a new date-time value based on adding an interval to the specified date. Testing validated that the DateParts listed in Table 1 are supported when using DateAdd in a WHERE clause in SMS WQL. The proper syntax for DateAdd follows:

    DateAdd ( DatePart, Number, Date )
    • DatePart is the part of the date you want to calculate (minute, day, month, and so on).

    • Number is the value to increment DatePart.

    • Date is a valid date-time value used to calculate the new date.

Table 1 shows the DataParts and their abbreviations.

As you can see, ConfigMgr provides a considerable amount of power in configuring queries. If you plan to create a custom query-based collection, first try to create a query using the Query Builder. Then take the next step, if necessary, to incorporate your custom query details. The next sections provide examples of using Extended WQL.

Example: Querying for Systems with a Hardware Scan in the Last 30 Days

Use this query to retrieve all systems that have reported a LastHardwareScan date within the last 30 days:

SELECT SMS_R_System.ResourceID,SMS_R_System.ResourceType,
SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,
SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client
FROM from SMS_R_System inner join
SMS_G_System_WORKSTATION_STATUS on
SMS_G_System_WORKSTATION_STATUS.ResourceID = SMS_R_System.ResourceId
WHERE DATEDIFF(dd,SMS_G_System_WORKSTATION_STATUS.LastHardwareScan,GetDate()) < 30


Notice the WHERE clause in the WQL statement, which is using the DateDiff function. The query uses dd to specify the difference in days, then the LastHardwareScan property is compared to the current date using GetDate(). If the difference in days is less than 30, the system is included in the query.

Example: Querying for Systems Discovered Since Midnight

The following example includes all systems discovered since midnight, based on the CreationDate property in the discovery record.

SELECT SMS_R_System.ResourceID,SMS_R_System.ResourceType,
SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier,
SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client
FROM SMS_R_System
WHERE (DateDiff(day, CreationDate, GetDate()) < 1)

Converting WQL to SQL

Now that you understand how to create queries using the Query Builder, you may also want to create these queries in ConfigMgr web reports. If you have built any web reports, you probably know that there is no query builder type of tool. It is not well known, but you can easily translate your WQL queries to SQL. As an example, look at the query created in Figure 1, which shows you the system name, AD site, total physical memory, and last hardware scan. The WQL looks like this:

select SMS_R_System.Name, SMS_R_System.ADSiteName,
SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory,
SMS_G_System_WORKSTATION_STATUS.LastHardwareScan from SMS_R_System inner join
SMS_G_System_X86_PC_MEMORY on
SMS_G_System_X86_PC_MEMORY.ResourceId = SMS_R_System.ResourceId
inner join SMS_G_System_WORKSTATION_STATUS on
SMS_G_System_WORKSTATION_STATUS.ResourceId = SMS_R_System.ResourceId


Figure 1. The General tab of a query to display memory information


To convert this WQL to SQL, simply execute the query. Next, review the smsprov.log on the site server, looking for a line that contains Execute SQL =. For this example, you would find a log entry similar to this:

[1398][Thu 03/26/2009 06:00:24]:Execute SQL =select
all SMS_R_System.Name0,SMS_R_System.AD_Site_Name0,
SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory0,
System_WORKSTATION_STATUS0.LastHWScan from System_DISC
AS SMS_R_System INNER JOIN PC_Memory_DATA AS SMS_G_System_X86_PC_MEMORY ON
SMS_G_System_X86_PC_MEMORY.MachineID = SMS_R_System.ItemKey INNER JOIN
WorkstationStatus_DATA AS System_WORKSTATION_STATUS0 ON
System_WORKSTATION_STATUS0.MachineID = SMS_R_System.ItemKey

Other -----------------
- Active Directory Domain Services 2008 : Modify a Group Object Managed By Properties & Modify a Group Object Protection from Deletion
- Active Directory Domain Services 2008 : Modify a Group Object’s Type & Modify a Group Object’s Members
- Windows Server 2003 : Managing WWW Sites (part 4) - HTTP Headers Tab & Custom Errors Tab
- Windows Server 2003 : Managing WWW Sites (part 3) - Directory Security Tab
- Windows Server 2003 : Managing WWW Sites (part 2) - Home Directory Tab & Documents Tab
- Windows Server 2003 : Managing WWW Sites (part 1) - Web Site Tab & Performance Tab
- Windows Server 2003 : Advanced Internet Information Services - Site-Level Administration & Directory-Level Administration
- Windows Server 2003 : Advanced Internet Information Services - Server-Level Administration
- Internet Security and Acceleration Server 2004 : Import, Export, Backup, and Restore
- Windows Server 2008 Server Core : Managing PnP Setups Using the PnPUtil Utility & Printing Data Files with the Print Utility
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server