如何创建更新列表
通过创建 SMS_AuthorizationList 类的实例并填充属性,在 Configuration Manager 中创建包含一组软件更新的更新列表。
创建更新列表
设置与 SMS 提供程序的连接。
使用
SMS_AuthorizationList
类创建新的更新列表对象。填充新的更新列表属性。
保存新的更新列表和属性。
示例
以下示例方法演示如何通过创建 类的实例并填充属性来创建包含一组软件更新的 SMS_AuthorizationList
更新列表。
重要
LocalizedInformation
此示例中使用的 属性需要一个对象数组 (嵌入数组) 说明信息。
在此示例中,属性 LocaleID
硬编码为英语 (美国) 。 如果需要非美国区域设置。安装,可以从 SMS_Identification 服务器 WMI 类LocaleID
属性获取它。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
以下示例演示 Visual Basic 中的子例程调用:
' Prework for CreateSUMUpdateList
' Create the array of CI_IDs.
dim newUpdates
newUpdates = Array(9)
' Create and populate an SMS_CI_LocalizedProperties object.
set SMSCILocalizedProperties = swbemservices.Get("SMS_CI_LocalizedProperties").SpawnInstance_
SMSCILocalizedProperties.Description = "Test Description"
SMSCILocalizedProperties.DisplayName = "Test Display Name"
SMSCILocalizedProperties.InformativeURL = "Test URL"
SMSCILocalizedProperties.LocaleID = "1033"
' Create an array to hold the SMS_CI_LocalizedProperties object.
dim newDescriptionInfo
newDescriptionInfo = Array(SMSCILocalizedProperties)
' Call the CreateSUMUpdateList method.
Call CreateSUMUpdateList(swbemServices, _
newUpdates, _
newDescriptionInfo)
以下示例显示了 C# 中的方法调用:
// Prework for CreateSUMUpdateList
// Create array list (to hold the array of Localized Properties).
List<IResultObject> newDescriptionInfo = new List <IResultObject>();
IResultObject SMSCILocalizedProperties = WMIConnection.CreateEmbeddedObjectInstance("SMS_CI_LocalizedProperties");
// Populate the initial array values (this could be a loop to added more localized info).
SMSCILocalizedProperties["Description"].StringValue = "4 CI_IDs - 9,34,53,72 ";
SMSCILocalizedProperties["DisplayName"].StringValue = "Test Display Name";
SMSCILocalizedProperties["InformativeURL"].StringValue = "Test URL";
SMSCILocalizedProperties["LocaleID"].StringValue = "1033";
// Add the 'embedded properties' to newDescriptionInfo.
newDescriptionInfo.Add(SMSCILocalizedProperties);
// Create the array of CI_IDs.
int[] newCI_ID = new int[] { 9, 34, 53, 72 };
// Call the CreateSUMUpdateList method.
SUMSnippets.CreateSUMUpdateList(WMIConnection,
newCI_ID,
newDescriptionInfo);
Sub CreateSUMUpdateList(connection, _
newUpdates, _
newDescriptionInfo)
' Create the new UpdateList object.
Set newUpdateList = connection.Get("SMS_AuthorizationList").SpawnInstance_
' Populate the UpdateList properties.
' Updates is an int32 array that maps to the CI_ID in SMS_SoftwareUpdate.
newUpdateList.Updates = newUpdates
' Need to pass embedded properties (LocalizedInformation) here.
newUpdateList.LocalizedInformation = newDescriptionInfo
' Save the new UpdateList and properties.
newUpdateList.Put_
' Output the new UpdateList name.
Wscript.Echo "Created Update List " & newUpdateList.LocalizedDisplayName
End Sub
public void CreateSUMUpdateList(WqlConnectionManager connection,
int [] newUpdates,
List<IResultObject> newDescriptionInfo)
{
try
{
// Create the new SMS_AuthorizationList object.
IResultObject newUpdateList = connection.CreateInstance("SMS_AuthorizationList");
// Populate the new SMS_AuthorizationList object properties.
// Updates is an int32 array that maps to the CI_ID in SMS_SoftwareUpdate.
newUpdateList["Updates"].IntegerArrayValue = newUpdates;
// Pass embedded properties (LocalizedInformation) here.
newUpdateList.SetArrayItems("LocalizedInformation", newDescriptionInfo);
// Save changes.
newUpdateList.Put();
Console.WriteLine();
Console.WriteLine("Created Update List. " );
}
catch (SmsException ex)
{
Console.WriteLine("Failed to create update list. Error: " + ex.Message);
throw;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
Connection |
-管理: WqlConnectionManager - VBScript: SWbemServices |
与 SMS 提供程序的有效连接。 |
newUpdates |
- 托管: Integer 数组- VBScript: Integer 数组 |
与更新列表关联的更新数组。 |
newDescriptionInfo |
- 托管: Object 数组- VBScript: Object 数组 |
对象数组 (类型的 LocalizedInformation 嵌入属性) 。 |
编译代码
此 C# 示例需要:
命名空间
System
System.Collections.Generic
System.Text
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
可靠编程
有关错误处理的详细信息,请参阅关于Configuration Manager错误。
.NET Framework 安全性
有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理。