I'm hoping there is someone out there with better WQL chops than me that can help with this rather complex query. Right now we have a query in place that takes all computers in configuration manager, looks at the primary users, checks to see if the primary user is in an AD group, and includes them in the collection if they are. What I need to do is either:
Example:
User2 and User3 are in ADGroup but User1 is not, so the WQL query should return only CompB and CompC.
Current WQL:
select distinct 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 JOIN SMS_UserMachineRelationship ON SMS_R_System.ResourceID=SMS_UserMachineRelationship.ResourceID JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName WHERE SMS_UserMachineRelationship.Types=1 AND SMS_UserMachineRelationship.IsActive=1 AND SMS_R_User.UserGroupName="DOMAIN\\GROUP"
I tried adding AND NOT SMS_R_User.UserGroupName!="DOMAIN\\GROUP" on the end of the query but that didn't have the right result, and I'm at the end of my WQL knowledge. Thanks in advance!
- exclude systems with multiple primary users
or - exclude systems if any of the primary users are not in the AD group (preferred)
Example:
| Computer | Primary Users |
| CompA | User1, User2, User3 |
| CompB | User2, User3 |
| CompC | User3 |
Current WQL:
select distinct 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 JOIN SMS_UserMachineRelationship ON SMS_R_System.ResourceID=SMS_UserMachineRelationship.ResourceID JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName WHERE SMS_UserMachineRelationship.Types=1 AND SMS_UserMachineRelationship.IsActive=1 AND SMS_R_User.UserGroupName="DOMAIN\\GROUP"
I tried adding AND NOT SMS_R_User.UserGroupName!="DOMAIN\\GROUP" on the end of the query but that didn't have the right result, and I'm at the end of my WQL knowledge. Thanks in advance!