How to Configure Package Properties
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
The following example shows how to configure the properties of an existing package, in System Center 2012 R2 Configuration Manager, by using the SMS_Package class.
To configure an existing package
Set up a connection to the SMS Provider.
Load the existing package object by using SMS_Package class.
Populate any package properties (this example uses package description).
Save the package and the new package properties.
Example
The following example method configures package properties for software distribution.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub ConfigurePackageProperties(connection, existingPackageID, newPackageDescription)
' Get the specific package object. Dim packageToConfigure
Set packageToConfigure = connection.Get("SMS_Package.PackageID='" & existingPackageID & "'")
' Replace the existing package property (in this case the package description).
packageToConfigure.Description = newPackageDescription
' Save the package with the modified properties.
packageToConfigure.Put_
' Output package ID and package name.
wscript.echo "Configured Package "
wscript.echo "Package ID: " & packageToConfigure.PackageID
wscript.echo "Package Name: " & packageToConfigure.Name
End Sub
public void ConfigurePackageProperties(WqlConnectionManager connection, string existingPackageID, string newPackageDescription) { try { // Get specific package instance to modify. IResultObject packageToConfigure = connection.GetInstance(@"SMS_Package.PackageID='" + existingPackageID + "'"); // Replace the existing package property with the new value (in this case the package description). packageToConfigure["Description"].StringValue = newPackageDescription; // Save package and modified package properties. packageToConfigure.Put(); // Output package ID and package name. Console.WriteLine("Configured Package "); Console.WriteLine("Package ID: " + packageToConfigure["PackageID"].StringValue); Console.WriteLine("Package Name: " + packageToConfigure["Name"].StringValue); } catch (SmsException ex) { Console.WriteLine("Failed to configure package. Error: " + ex.Message); throw; } }
Compiling the Code
The C# example requires:
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
The example method has the following parameters:
Parameter
Type
Description
connection
swbemServices
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
existingPackageID
Managed: String
VBScript: String
The ID of the existing package.
newPackageDescription
Managed: String
VBScript: String
The description for the new package.