How to Add an Operating System Install 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
You add an operating system install package to System Center 2012 R2 Configuration Manager by creating and populating an instance of SMS_OperatingSystemInstallPackage Server WMI Class.
To add an operating system install 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_OperatingSystemInstallPackage.
Set at least the Name, PkgSourceFlag and PkgSourcePath properties.
Commit the changes.
Example
The following example method adds an operating system install package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub AddOSInstallPackage(connection, name, description, path)
Dim osInstallPackage
Set osInstallPackage = connection.Get("SMS_OperatingSystemInstallPackage").SpawnInstance_()
' Populate the new package properties.
osInstallPackage.Name = name
osInstallPackage.Description = description
osInstallPackage.PkgSourceFlag=2
osInstallPackage.PkgSourcePath = path
' Write the package.
osInstallPackage.Put_
End Sub
public void AddOSInstallPackage( WqlConnectionManager connection, string name, string description, string path) { try { // Create new operating system image package object. IResultObject osInstallPackage = connection.CreateInstance("SMS_OperatingSystemInstallPackage"); // Populate operating system package properties. osInstallPackage["Name"].StringValue = name; osInstallPackage["Description"].StringValue = description; osInstallPackage["PkgSourceFlag"].IntegerValue = (int)PackageSourceFlag.StorageDirect; osInstallPackage["PkgSourcePath"].StringValue = path; // Save operating system package. osInstallPackage.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.
name
Managed: String
VBScript: String
Name for the new operating system image package.
description
Managed: String
VBScript: String
Description for the operating system image package.
path
Managed: Integer
VBScript: Integer
Universal Naming Convention (UNC) path to the image Windows Image (WIM) file.