Skip to content

Latest commit

 

History

History
75 lines (58 loc) · 3.98 KB

how-to-delete-a-configuration-manager-object-by-using-wmi.md

File metadata and controls

75 lines (58 loc) · 3.98 KB
title titleSuffix description ms.date ms.subservice ms.service ms.topic ms.assetid author ms.author manager ms.localizationpriority ms.collection ms.reviewer
Delete an Object by Using WMI
Configuration Manager
To delete a Configuration Manager object, call the SWbemObject object Delete_ method.
09/20/2016
sdk
configuration-manager
how-to
e843aaf1-f278-447d-82b1-642f4286b65d
Banreet
banreetkaur
apoorvseth
low
tier3
mstewart,aaroncz

How to Delete a Configuration Manager Object by Using WMI

To delete a Configuration Manager object, in Configuration Manager, call the SWbemObject object Delete_ method.

To delete a Configuration Manager object

  1. Set up a connection to the SMS Provider. For more information, see How to Connect to an SMS Provider in Configuration Manager by Using WMI.

  2. Using the SWbemServices object you obtain from step one, call the Get method and specify the class and key information for the object you want to delete. Get returns a SWbemObject that represents the object.

  3. Using the SWbemObject, call Delete to delete the object.

Example

The following VBScript code example deletes the package (SMS_Package) identified by its package identifier packageID.

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

Sub DeletePackage (connection, packageID)  

    On Error Resume Next   
    Dim package  

    Set package = connection.Get("SMS_Package.PackageID='" & packageID & "'")  
    If Err.Number<>0 Then  
        Wscript.Echo "Couldn't get package " + packageID  
        Exit Sub  
    End If  

    package.Delete_  

    WScript.Echo "Package deleted"  

    If Err.Number<>0 Then  
        Wscript.Echo "Couldn't delete " + packageID  
        Exit Sub  
    End If  

End Sub  

This example method has the following parameters:

Parameter Type Description
connection SWbemServices A valid connection to the SMS Provider.
packageID String The package identifier. This is obtained from the SMS_Package class PackageID.

See Also

Windows Management Instrumentation
Objects overview How to Call a Configuration Manager Object Class Method by Using WMI
How to Connect to an SMS Provider in Configuration Manager by Using WMI
How to Create a Configuration Manager Object by Using WMI
How to Modify a Configuration Manager Object by Using WMI
How to Perform an Asynchronous Configuration Manager Query by Using WMI
How to Perform a Synchronous Configuration Manager Query by Using WMI
How to Read a Configuration Manager Object by Using WMI
How to Read Lazy Properties by Using WMI