我需要实现应用程序以将设备名称添加到规则 SMS_CollectionRuleQuery 上的查询表达式并使用 SCCM 2007 SDK 保存它。我希望必须使用 Put() 方法来保存查询表达式,但似乎修改不保存!
有什么好的保存方法?
谢谢
菲利普。
片段代码:
using System;
using System.Collections.Generic;
using Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine;
using Microsoft.ConfigurationManagement.ManagementProvider;
using System.Management;
public class SCCM_Try_Change_QueryExpression
{
public static void RunSnippet()
{
// Connect on SCCM 2007
SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();
WqlConnectionManager connection = new WqlConnectionManager(namedValues);
connection.Connect("blabla", "blabla", "blabla");
// Get collection CS10001E
IResultObject collection = connection.GetInstance((@"SMS_Collection.CollectionID='CS10001E'"));
// Get Rules
ManagementBaseObject smsCollection = (ManagementBaseObject) collection["CollectionRules"].ObjectArrayValue [0];
WL ("Rule Type="+smsCollection.ClassPath.ClassName);
WL ("\nOriginal Query="+smsCollection["QueryExpression"].ToString ());
// Change query : add devicename XXXXX
string newQuery = smsCollection["QueryExpression"].ToString ().Replace (" ( \""," ( \"XXXXX\",\"");
smsCollection.SetPropertyValue("QueryExpression", newQuery);
WL ("\nNew Query="+smsCollection["QueryExpression"].ToString ());
// Save change
collection.Put();
}
}
应用程序输出:
Rule Type=SMS_CollectionRuleQuery
Original Query=select <...> from SMS_R_System where Name in ( "D07CAU" ) order by Name
New Query=select <...> from SMS_R_System where Name in ( "XXXXX","D07CAU" ) order by Name
Press any key to continue...
当我重新启动应用程序时,原始查询不包括我的新设备名称“XXXXX”
Original Query=select <...> from SMS_R_System where Name in ( "D07CAU" ) order by Name