You add an operating system install package to System Center 2012 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.
Visual Basic Script | ![]() |
---|---|
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 |
C# | ![]() |
---|---|
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; } } |
The example method has the following parameters:
Parameter |
Type |
Description |
connection |
|
A valid connection to the SMS Provider. |
name |
|
Name for the new operating system image package. |
description |
|
Description for the operating system image package. |
path |
|
Universal Naming Convention (UNC) path to the image Windows Image (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.