Creating dynamic collection by selecting objects not in a collection

If you are interested in a way of retrieving objects into a collection that don't exist in another collection, it's actually not very difficult. For example, you have a collection of clients with antivirus. Now you want to create a collection of clients that do not have antivirus. Instead of creating a new one, you run subselect to bring back all the clients that are not in the original antivirus collection.

The only thing you have to know is the collection id of the collection that you want to check. For the samples below, note that [collid] is a generic tag for your collection ids. If you examine the root\sms\site_ of your sms server, you'll see a list of sms collections labeled with:


This is what you need to build your subselect query. If you query this in wbemtest, with something like select * from sms_cm_res_coll_[collid] you should get back a list of resource ids which look something like this

or something similar... I was showing that part just to demonstrate that querying the collection id from wmi in this manner, does indeed produce the members of the collection. now to put it all together, this is how you'd build your subselect query

select sms_r_system.resourceid,
from sms_r_system
where resourceid not in
select sys.resourceid
from sms_cm_res_coll_[collid] AS coll, sms_r_system as sys
where sys.resourceid = coll.resourceid

In effect, this would be the same as building a collection that's limited to another collection. the only difference is that when you're using limiting collections, you can't specify to retrieve where a machine doesn't exist in a certain collection. 


Post a Comment