SCCM – Creating Device Collection using OU

Query:

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 where SMS_R_System.SystemOUName = “DOMAIN.LOCAL/OU1

If you have sub-OUs, and would like to exclude those sub-OUs from your query, you can add the following:

and SMS_R_System.ResourceID Not In (Select ResourceID from SMS_R_System Where SystemOUName like  “DOMAIN.LOCAL/OU1/SUB-OU-1-TO-EXCLUDE” or SystemOUName like “DOMAIN.LOCAL/OU1/SUB-OU-2-TO-EXCLUDE”)

So the entire Query would look something like:

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 where SMS_R_System.SystemOUName = “DOMAIN.LOCAL/OU1” and SMS_R_System.ResourceID Not In (Select ResourceID from SMS_R_System Where SystemOUName like  “DOMAIN.LOCAL/OU1/SUB-OU-1-TO-EXCLUDE” or SystemOUName like “DOMAIN.LOCAL/OU1/SUB-OU-2-TO-EXCLUDE”)

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s