You create a Configuration Manager object, in Microsoft System Center Configuration Manager 2007, by calling the SWbemObject object SpawnInstance method.

The SWbemObject is the class definition for the object type that you want to create. For example, SMS_Package.You get the SWBemObject by calling the SWBemServices object Get method.

To create 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 Get to get the SWbemObject for the Configuration Manager object class definition.

  3. Call SpawnInstance on the SWbemObject to create the new object. A SWbemObject is returned for the new object.

  4. Using the SWbemObject returned from the call to SpawnInstance, populate the object properties.

  5. Call Put to commit the new object to the SMS Provider.


The following VBScript code example creates an SMS_Package object.

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

Visual Basic Script  Copy Code
Sub CreatePackage (connection)

	On Error Resume Next

	' Create a package object.
	Set package = connection.Get("SMS_Package").SpawnInstance_()

	If Err.Number<>0 Then
		Wscript.Echo "Couldn't create packages object"
		Exit Sub
	End If

	' Populate the object.
	package.Name = "Test Package"
	package.Description = "A test package"
	package.PkgSourceFlag = 2
	package.PkgSourcePath = "C:\temp"


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

	WScript.Echo "Package created"
End Sub

This example method has the following parameters:

Parameter Type Description



A valid connection to the SMS Provider.

Compiling the Code

See Also

Send comments about this topic to Microsoft.