Freigeben über


How to Create a Custom Report

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

You create a custom report, in Microsoft System Center Configuration Manager 2007, by creating an instance of the SMS_Report class and populating the properties.

To create a custom report

  1. Set up a connection to the SMS Provider.

  2. Create the new update list object by using the SMS_Report class.

  3. Populate the new report properties.

  4. Save the new report and properties.

Example

The following example method shows how to create a custom report update by creating an instance of the SMS_Report class and populating the properties.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub CreateReport(connection,       _
                 newReportName,    _
                 newCategory,      _
                 newSQLQuery)               

    ' Create the new report object. 
    Set newReport = connection.Get("SMS_Report").SpawnInstance_
    
    ' Populate the SMS_Report properties.
    newReport.Name = newReportName
    newReport.Category = newCategory
    newReport.SQLQuery =  newSQLQuery
            
    ' Save the new report and properties.
    newReport.Put_ 
    
    ' Output new report name.
    Wscript.Echo "Created new report: " & newReportName                  
                                    
End Sub
public void CreateReport(WqlConnectionManager connection, 
                         string newReportName, 
                         string newCategory, 
                         string newSQLQuery)
{            
    try
    {
        // Create new report object.
        IResultObject newReport = connection.CreateInstance("SMS_Report");

        // Populate new report properties.
        newReport["Name"].StringValue = newReportName;
        newReport["Category"].StringValue = newCategory;
        newReport["SQLQuery"].StringValue = newSQLQuery;
        
        // Save new report and new report properties.
        newReport.Put();

        // Output new report name.
        Console.WriteLine("Created report" + newReport["Name"].StringValue);
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to create report. Error: " + ex.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter

Type

Description

Connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

newReportName

  • Managed: String

  • VBScript: String

A string indicating the name of the new report.

newCategory

  • Managed: String

  • VBScript: String

A string indicating the category to be used in the Configuration Manager console to filter the list of reports and to provide a report hierarchy. The default value is "".

newSQLQuery

  • Managed: String

  • VBScript: String

A string with the text of the SQL query that produces the result set of the report.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Concepts

System Center Configuration Manager Software Development Kit
Configuration Manager Reporting
SMS_Report Server WMI Class