If you are using User Device Affinity--associating a user with one or more specified devices for application deployment to make sure the application install on all devices that are associated with that user,it is necessary to identify the computers which do not have primary User Defined.More about User Define Affinity http://technet.microsoft.com/en-us/library/gg699365.aspx.
Create collection using below WQL query for list of computers with Primary Device is NULL.(Make sure you limit the collection to computers with Client installed and Active) else you will get all computers who do not have sccm client installed .
WQL query uses wmi class (SMS_UserMachineRelationship) which store the information only about UDA relationship. Usermachinerelationship will not have any entries for computers do not have UDA relationship.
so I use subselected query using not in function.Get list of computers for which UDA relationship is not null and compare them with v_r_system active clients.
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.ResourceId not in (select resourceid from SMS_UserMachineRelationship where UniqueUserName is not null)
Updated: There was a question on myitform recently ,asking for Users (collection or SQL Report) without Device affinity set.
For User collection :
Select * From SMS_R_User where UniqueUserName not in (Select UniqueUserName from SMS_UserMachineRelationship)
For SQL Report:
vru.Full_User_Name0 as [Full Name]
from v_R_User vru
where vru.ResourceID not in (select vru.ResourceID
from v_UsersPrimaryMachines upm
left join v_R_User vru on upm.UserResourceID = vru.ResourceID
where vru.Name0 IS NOT NULL
Thanks to Ryan and John.
Hope it helps.