The following example shows how to create a package and program by using a package definition file template in System Center 2012 Configuration Manager. The package definition file template contains the default values that are used to create SMS_Package and SMS_Program objects. The following example uses the SMS_PDF_Package class and the GetPDFData method to load the package definition file template information and to create a package and the related programs.

To create a package by using a package definition file template

  1. Set up a connection to the SMS Provider.

  2. Create the new package object by using the SMS_PDF_Package class.

  3. Populate any additional package properties.

  4. Load the program information and associate each program with the package.


The following example method creates a new package by using a package definition file.

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

Visual Basic Script  Copy Code
Sub SWDCreatePDFPackage(connection, existingPDF_ID, newPackageSourceFlag, newPackageSourcePath)
	' The PDF_ID must be passed in.
	' The PDF_ID can be identified through the SMS_PDF_Package class.

	Dim newPDFPackage
	Dim returnCode
	Dim newPackage
	Dim newPackagePath
	Dim packageID
	Dim program
	Dim arrayOfPrograms

	' Package Creation
	' ----------------	 
	' Create new SMS_PDF_Package instance.
	Set newPDFPackage = connection.Get("SMS_PDF_Package")

	' Load the Package Definition File data using the GetPDFData method.
	returnCode = newPDFPackage.GetPDFData(existingPDF_ID, newPackage, arrayOfPrograms)

	' Assign any additional package properties.
	newPackage.PkgSourceFlag = newPackageSourceFlag
	newPackage.PkgSourcePath = newPackageSourcePath

	' Save the package path and get the Package ID.
	Set newPackagePath = newPackage.Put_
	packageID = newPackagePath.Keys("PackageID")

	' Program Creation 
	' -----------------
	' Enumerate through the program array and create the programs.
	For Each program In arrayOfPrograms
		program.PackageID = packageID

End Sub

The example method has the following parameters:

Parameter Type Description


  • VBScript: SWbemServices

A valid connection to the SMS Provider.


  • VBScript: Integer

ID of the package definition file.


  • VBScript: Integer

The package source.


  • VBScript: String

The path to the package source.

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

See Also