Share via


How to Delete a 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 delete a report, in Microsoft System Center Configuration Manager 2007, by getting an existing instance of the SMS_Report class and calling the delete method.

To delete a report

  1. Set up a connection to the SMS Provider.

  2. Load the existing report by using the SMS_Report class and an existing report ID.

  3. Delete the report by using the delete method.

Example

The following example method shows how to delete a report by getting an existing instance of the SMS_Report class and calling the delete method.

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

Sub DeleteReport(connection,        _
                 existingReportID)   

    ' Get an existing report, identified by ReportID, to delete. 
    Set existingReport = connection.Get("SMS_Report.ReportID=" & existingReportID)  
    
    ' Get report name for output.
    reportName = existingReport.Name
       
    ' Delete the report.
    existingReport.Delete_
    
    ' Output a success message.
    Wscript.Echo "Deleted report: " & existingReportID
    Wscript.Echo "Report name: "    & reportName
                                   
End Sub
public void DeleteReport(WqlConnectionManager connection, 
                         string existingReportID)
{            
    try
    {
        // Get the specified report instance (passed in as existingReportID).
        IResultObject reportToDelete = connection.GetInstance(@"SMS_Report.ReportID=" + existingReportID);

        // Delete the report instance.
        reportToDelete.Delete();

        // Output report ID of deleted report.
        Console.WriteLine("Deleted Report ID: " + existingReportID);
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to delete 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.

exisitingReportID

  • Managed: Integer

  • VBScript: Integer

A value identifying the existing report. In the code example, this value is passed as a string to simplify querying for the report instance.

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