In System Center 2012 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.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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; } } |
The example method has the following parameters:
Parameter |
Type |
Description |
connection |
|
A valid connection to the SMS Provider. |
newImagePackageName |
|
The new image package name. |
newImagePackageDescription |
|
The new image package description |
newImagePackageSourcePath |
|
The UNC path to the WIM file. |
Compiling the Code
The C# example has the following compilation requirements:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.