我试图通过我们的应用程序将新设备添加到SCCM时,针对SMS_Collection调用RequestRefresh函数。但是当我调用execute时,我得到以下异常。
Main: Unrecoverable Service Error.|System.Management.ManagementException Invalid method Parameter(s)
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at SccmProxy.Adapter.RefreshCollection(String collectionName) in c:\ws\development\SCCMAgent\Main\SccmProxy\SccmProxy\Adapter.cs:line 733
at SccmProxy.TestHelper.ExecuteTest(ProxyConfiguration config) in c:\ws\development\SCCMAgent\Main\SccmProxy\SccmProxy\TestHelper.cs:line 144
at SccmProxy.Service.Main() in c:\ws\development\SCCMAgent\Main\SccmProxy\SccmProxy\Service.cs:line 134 Void ThrowWithExtendedInfo(System.Management.ManagementStatus)
这是代码
ManagementPath pathMethod = new ManagementPath("SMS_Collection");
using (ManagementClass processClass = new ManagementClass(this.Configuration.NewTargetScope, pathMethod, null))
{
ManagementBaseObject inParams = processClass.GetMethodParameters("RequestRefresh");
using (ManagementBaseObject outParams = processClass.InvokeMethod("RequestRefresh", inParams, null))
{
LOGGER.Info(MethodBase.GetCurrentMethod().Name, "Successful collection refresh: {0}", outParams["ReturnValue"]);
}
}
问题在于,当我调用GetMethodParameters时,它返回一个带有参数的对象,该参数名为" includesubcollections"这对于2007 SCCM有效但我使用2012 SCCM并且RequestRefresh方法不再使用该参数。当GetMethodCall指向新的2012 SCCM实例时,它是如何返回旧的函数参数的呢?
答案 0 :(得分:0)
我无法使用上面的代码,但是可以使用http://msdn.microsoft.com/en-us/library/hh949402.aspx
中的示例通过Wql调用RequestRefreshpublic void RefreshCollection(WqlConnectionManager connection, string collectionID)
{
IResultObject collection = connection.GetInstance(string.Format("SMS_Collection.CollectionID='{0}'", collectionID));
collection.ExecuteMethod("RequestRefresh", null);
}