Here’s a great script I thought about sharing since I find it to be very handy to assist for the following requirement.

Create a “all computers” collection for software updates and exclude various OU’s that have computers not allowed to be updated for various reasons. Please modify the RED areas with the correct information. The great part is, you don’t have to spell out the full OU name to be excluded.

Script

select sys.ResourceId, sys.ResourceType, sys.Name, sys.SMSUniqueIdentifier, sys.ResourceDomainORWorkgroup, sys.Client
from SMS_R_System as sys where sys.SystemOUName like "TEST.COM/COMPUTERACCOUNTS"
and sys.ResourceId not in (select ResourceID from  SMS_R_System where SMS_R_System.SystemOUName like "%OuNameToNotInclude")
and sys.ResourceId not in (select ResourceID from  SMS_R_System where SMS_R_System.SystemOUName like "%OuNameToNotInclude")
and sys.ResourceId not in (select ResourceID from  SMS_R_System where SMS_R_System.SystemOUName like "%OuNameToNotInclude")