How to run query in a limited collection
Hi, We have some problem to run a query in SCCM 2007, limiting the result to a given collection. In the SCCM console we can specify an IdCollection to limit the execution of the SMS_Query object on a collection. The limitation is Ok when the query is executed from the console (by double clicking on it). We would like to run such query form .NET. After some research, it seems that there are 2 options : * Option 1 : making a join with SMS_CM_RES_COLL_%idCollection% IResultObject result = connection.QueryProcessor.ExecuteQuery(query["Expression"].StringValue + " inner join SMS_CM_RES_COLL_D010000D as COL ON SMS_R_SYSTEM.RESOURCEID=COL.RESOURCEID"); We don't like this option, as we are not sure that the concatenation will always result ina runnable query (for ex, the original query may include a "Where" clause). * Option 2 : use the context : connection.Context.Add("LimitToCollectionIDs",query["LimitToCollectionID"].StringValue); IResultObject result = connection.QueryProcessor.ExecuteQuery(query["Expression"].StringValue); This option does not work, even if we add the context as a second parameter of the ExecuteQuery call : IResultObject result = connection.QueryProcessor.ExecuteQuery(query["Expression"].StringValue, connection.Context); In option 2, the result always includes the full set of machines (no collection filtering). Unfortunately, it is the option that we would like to use, as it seems to be a more reliable one. Does anybody already succeeded in executing a query witha collection limitation ? Did you use option 1, or is option 2 supposed to work, and if yes, how ? Thanks for your help, Sylvain L
November 3rd, 2008 4:35pm

Make sure the "object" in the Context Dictionary is a string array string[] sArray = new string[1]; sArray[0] = "SMS00001"; //Collection ID connection.Context.Add("LimitToCollectionIDs", sArray); //note second parameter is an array. If you add more collectionIds to the array, a join will be performed, so that the result is limited to the intersection of all the CollectionIDs provided.
Free Windows Admin Tool Kit Click here and download it now
November 1st, 2010 9:15pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics