Friday, September 5, 2008

More Excluding Collections

Say you want to create a collection that will be all computer except certian OUs and maybe some other computers:

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Name not in (select distinct SMS_G_System_COMPUTER_SYSTEM.Name from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_R_System.SystemOUName = "domain/OU/OU" or SMS_R_System.SystemOUName = "domain/OU/OU2" or SMS_G_System_COMPUTER_SYSTEM.Name = "computer2")

now this assumes 1 computer. You could add multiple " or SMS_G_System_COMPUTER_SYSTEM.Name = "computer2") " but this is not really a well formed statement. Other ways to do this is use the "or SMS_G_System_COMPUTER_SYSTEM.Name in ("computer2","computer3") " and so forth.

Don't forget you can also do something like this if you want to exclude an entire collection :

and ResourceId not in (select ResourceID from SMS_CM_RES_COLL_XXXxxxxx)

More cross link of exclusions
http://sms-hints-tricks.blogspot.com/2008/10/exclusions-based-on-group-or-ou.html