You create a Configuration Manager object, in System Center 2012 R2 Configuration Manager, 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
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.
Using the SWbemServices object you obtain from step one, call Get to get the SWbemObject for the Configuration Manager object class definition.
Call SpawnInstance on the SWbemObject to create the new object. A SWbemObject is returned for the new object.
Using the SWbemObject returned from the call to SpawnInstance, populate the object properties.
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" package.Put_ 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:
A valid connection to the SMS Provider.
Compiling the Code
TasksHow 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 Delete 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
ConceptsConfiguration Manager Objects Overview
How to Use Configuration Manager Objects with WMI