Muokkaa

Jaa


How to Modify a Configuration Manager Object by Using WMI

You modify a Configuration Manager object, in Configuration Manager, by using the object's SWbemObject object to change its properties.

To modify 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. This returns a SWbemObject representing object.

  3. Using the SWbemObject, update the object properties.

  4. Call Put_ to update the object in the SMS Provider.

Example

The following VBScript code example gets a package (SMS_Package) object, changes the package description, and then commits the changes back to the SMS Provider. In this example, the package is retrieved through a call to the SWbemServices object Get. You can also retrieve the package by using a query. For more information, see How to Perform a Synchronous Configuration Manager Query by Using WMI.

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

Sub ModifyPackageDescription (connection, packageID, description)  

    On Error Resume Next   
    Dim package  

    ' Get the 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  

    Wscript.Echo "Package Name: " + package.Name  
    Wscript.Echo "Current Description: " + package.Description  

    ' Update and commit the package.  
    package.Description = description  

    package.Put_  
    If Err.Number<>0 Then  
        WScript.Echo "Couldn't commit the package"  
        Exit Sub  
    End If  

    Wscript.Echo "New Description: " + package.Description  
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 available from the SMS_Package class PackageID identifier.
Description String A new description for the object.

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 Delete 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