How to List Reports

System Center

Updated: October 28, 2009

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 list dashboards, in Microsoft System Center Configuration Manager 2007, by loading all instances of the SMS_Report class and then enumerating the instances, outputting specific properties as required.

To list reports

  1. Set up a connection to the SMS Provider.

  2. Load all instances of the SMS_Report class into a collection.

  3. Enumerate the collection of SMS_Report instances and output any properties as required.

Example

The following example method shows how to list reports by loading all instances of the SMS_Report class and then enumerating the instances, outputting specific properties as required.

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


Sub ListAllReports(connection)

' Build query to get all reports.
allReportsQuery = "SELECT * FROM SMS_Report"
    
' Run query.
Set allReports = connection.ExecQuery(allReportsQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

' Output report name and other properties for each report found.
For Each report in allReports
    
    wscript.echo "Report Name: "          & report.Name
    wscript.echo "ReportID:    "          & report.ReportID
    wscript.echo "Report GUID: "          & report.ReportGUID   
    wscript.echo " "
    
Next

End Sub


public void ListAllReports(WqlConnectionManager connection)
{
    try
    {
        // Get a collection of all SMS_Report instances.
        IResultObject allReports = connection.QueryProcessor.ExecuteQuery("select * from SMS_Report");

        foreach (IResultObject report in allReports)
        {
            Console.WriteLine("Report Name: " + report["Name"].StringValue);
            Console.WriteLine("Report ID:   " + report["ReportID"].IntegerValue);
            Console.WriteLine("Report GUID: " + report["ReportGUID"].StringValue);
            Console.WriteLine(" ");
        }
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to list reports. 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.

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

Show: