每当通过我们的应用程序将新设备添加到 SCCM 时,我都会尝试针对 SMS_Collection 调用 RequestRefresh 函数。但是,当我调用执行时,我得到以下异常。
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 实例时,它是如何返回旧函数参数的?