| title | Update an OS Image Package |
|---|---|
| description | Update an operating system using a Windows Image file that is associated with the operating system package in Configuration Manager. |
| ms.date | 09/20/2016 |
| ms.subservice | sdk |
| ms.topic | how-to |
| ms.collection | tier3 |
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.
-
Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.
-
Get the
SMS_ImagePackageclass instance you want to update. -
Call the
ReloadImagePropertiesclass instance method. -
Commit the
SMS_ImagePackageclass instance.
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 Subpublic 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. |
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
For more information about error handling, see About Configuration Manager Errors.
For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.