How to Add an Operating System Image Package in Configuration Manager
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
In System Center 2012 R2 Configuration Manager, you add an operating system image package by creating an instance of SMS_ImagePackage class. The path to the Windows Image (WIM) file is specified in the PkgSourcePath property as a Universal Naming Convention (UNC) path.
To create an operating system image package
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Create an instance of SMS_ImagePackage.
Specify the path to the WIM file in PkgSourcePath.
Commit the SMS_ImagePackage class instance.
Example
The following example method creates an operating system package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub AddOSImagePackage(connection, newImagePackageName, newImagePackageDescription, newImagePackageSourcePath)
Dim newImagePackage
Set newImagePackage = connection.Get("SMS_ImagePackage").SpawnInstance_()
' Populate the new package properties.
newImagePackage.Name = newImagePackageName
newImagePackage.Description = newImagePackageDescription
newImagePackage.PkgSourceFlag = 2
newImagePackage.PkgSourcePath = newImagePackageSourcePath
' Save the package.
newImagePackage.Put_
End Sub
public void AddOSImagePackage( WqlConnectionManager connection, string newImagePackageName, string newImagePackageDescription, string newImagePackageSourcePath) { try { // Create new package object. IResultObject newImagePackage = connection.CreateInstance("SMS_ImagePackage"); // Populate new package properties. newImagePackage["Name"].StringValue = newImagePackageName; newImagePackage["Description"].StringValue = newImagePackageDescription; newImagePackage["PkgSourceFlag"].IntegerValue = (int)PackageSourceFlag.StorageDirect; newImagePackage["PkgSourcePath"].StringValue = newImagePackageSourcePath; // Save new package and new package properties. newImagePackage.Put(); } catch (SmsException e) { Console.WriteLine(); Console.WriteLine("Failed to create package. Error: " + e.Message); throw; } }
Compiling the Code
The C# example has the following compilation requirements:
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.
The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
newImagePackageName
Managed: String
VBScript: String
The new image package name.
newImagePackageDescription
Managed: String
VBScript: String
The new image package description
newImagePackageSourcePath
Managed: String
VBScript: String
The UNC path to the WIM file.