Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Query Based Collection Multiple OU

Mahmoud87

Well-Known Member
Messages
66
Solutions
3
Reaction score
7
Points
8
Hi guys

I have created a query based collection for a single OU and it works perfectly fine, tried to edit the query and made it to grab the data off 2 organisational units, but it fails and doesn't collect grab machines. I have removed the extra bit I have added to the query and the collection works fine again no problems.

How to get a query based collection work on multiple OUs?

Here is the query I am using, which doesn't get any data from the OUs

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 = "XXX.local/divisions/XXX/computers/XXX" and SMS_R_System.SystemOUName="XXX.local/divisions/XXX/computers/hr"
 
Hi guys

I have created a query based collection for a single OU and it works perfectly fine, tried to edit the query and made it to grab the data off 2 organisational units, but it fails and doesn't collect grab machines. I have removed the extra bit I have added to the query and the collection works fine again no problems.

How to get a query based collection work on multiple OUs?

Here is the query I am using, which doesn't get any data from the OUs


Ok I got a work around, I have created another separate query in the collection to grab the machines of the 2nd OU.

upload_2017-9-21_15-9-26.png

I am still curious if it's possible to do it in one query?
 
Hi Mahmoud87,

You must use the "OR" operator instead of "AND" :

Code:
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 = "XXX.local/divisions/XXX/computers/XXX" or SMS_R_System.SystemOUName="XXX.local/divisions/XXX/computers/hr"
 
Hi Mahmoud87,

You must use the "OR" operator instead of "AND" :

Code:
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 = "XXX.local/divisions/XXX/computers/XXX" or SMS_R_System.SystemOUName="XXX.local/divisions/XXX/computers/hr"


Legend bro. this worked perfectly fine. Can you please explain why "OR" worked instead of "AND", is there any explanation for this. Thanks again mate.
 
Legend bro. this worked perfectly fine. Can you please explain why "OR" worked instead of "AND", is there any explanation for this. Thanks again mate.
Pretty simple, you cant have a computer in two different OU and unless if you can do that then your query with AND will work.

To satisfy the condition AND means that your computer account is in Corporate Admin OU and HR OU (which is not possible).
OR means either one of the OUs.
 
Back
Top