How to Delete a Package
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
The following example shows how to delete a package in System Center 2012 R2 Configuration Manager by using the SMS_Package class.
Note |
|---|
Any reference to this package, such as an advertisement or task sequence, should be cleaned up before deleting the package |
To delete a package
Set up a connection to the SMS Provider.
Load the existing package object by using the SMS_Package class.
Delete the package by using the delete method.
Example
The following example method deletes an existing package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub DeleteAPackage(connection, existingPackageID)
' Get the specified package instance (passed in as existingPackageID). Dim packageToDelete
Set packageToDelete = connection.Get("SMS_Package.PackageID='" & existingPackageID & "'")
' Delete the package.
PackageToDelete.Delete_
' Output package ID of deleted package.
wscript.echo "Deleted Package ID: " & existingPackageID
End Sub
public void DeleteAPackage(WqlConnectionManager connection, string existingPackageID) { try { // Get the specified package instance (passed in as existingPackageID). IResultObject packageToDelete = connection.GetInstance(@"SMS_Package.PackageID='" + existingPackageID + "'"); // Delete the package instance. packageToDelete.Delete(); // Output package ID of deleted package. Console.WriteLine("Deleted Package ID: " + existingPackageID); } catch (SmsException ex) { Console.WriteLine("Failed to create package. Error: " + ex.Message); throw; } }
Compiling the Code
The C# example requires:
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.

The example method has the following parameters:
Parameter
Type
Description
connection
swbemServices
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
existingPackageID
Managed: String
VBScript: String
The ID of the existing package.