How to Update an Operating System Image Package in Configuration Manager
In Configuration Manager, you update the Windows Image (WIM) file that is associated with the operating system package by calling the image package's SMS_ImagePackage class instance ReloadImageProperties method. The image is updated based on the location defined in the pkgSourcePath
property.
To update an operating system image package
Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.
Get the
SMS_ImagePackage
class instance you want to update.Call the
ReloadImageProperties
class instance method.Commit the
SMS_ImagePackage
class instance.
Example
The following example updates an operating system image package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub UpdateOSImage(connection,imagePackageID, sourcePath)
Dim imagePackage
' Get the image.
set imagePackage = connection.Get("SMS_ImagePackage.PackageID='" & imagePackageID & "'")
' Update the source.
imagePackage.PkgSourcePath=sourcePath
imagePackage.Put_
imagePackage.RefreshPkgSource
End Sub
public void UpdateOSImage(
WqlConnectionManager connection,
string imagePackageId,
string sourcePath)
{
try
{
// Get the image package.
IResultObject imagePackage = connection.GetInstance(@"SMS_ImagePackage.PackageID='" + imagePackageId + "'");
// Update the location.
imagePackage["PkgSourcePath"].StringValue = sourcePath;
imagePackage.Put();
imagePackage.ExecuteMethod("RefreshPkgSource", null);
}
catch (SmsException e)
{
Console.WriteLine(e.Message);
throw;
}
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection |
- Managed: WqlConnectionManager - VBScript: SWbemServices |
A valid connection to the SMS Provider. |
imagePackageID |
- Managed: String - VBScript: String |
The package image identifier. It is available from SMS_ImagePackage. PackageID . |
sourcePath |
- Managed: String - VBScript: String |
The path to the image package source in Universal Naming Convention (UNC) format. |
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.
.NET Framework Security
For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.