| title | Create an Object by Using WMI |
|---|---|
| description | Create a Configuration Manager object by calling the SWbemObject object SpawnInstance_ method. |
| ms.date | 09/20/2016 |
| ms.subservice | sdk |
| ms.topic | how-to |
| ms.collection | tier3 |
You create a Configuration Manager object, in 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.
-
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. An 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.
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 SubThis example method has the following parameters:
| Parameter | Type | Description |
|---|---|---|
Connection |
SWBemServices | A valid connection to the SMS Provider. |
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 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