Primary User and Device relationships in ConfigMgr are something that’s not very easy to make out in the ConfigMgr console for the administrator, at least not for a collection of Devices or Users. For instance I’ve been longing for the ability to show the Primary User or Primary Device as a column in the Device Collections and User Collections nodes in the console ever since ConfigMgr 2012 was released. Last week I was at a customer site and was tasked with determining what relationships between a Device and a Primary User was assigned by an administrator. In order to determine that, I started looking at the different WMI Server classes and found the SMS_UserMachineRelationship. This class holds all the relationships between a Device and the Primary User that’s been assigned by any assignment source. What do I mean by assignment source you may ask?
There’s a property called Sources for every instance in the SMS_UserMachineRelationship class. This property is an array of assignment sources. It holds an array of integers where each integer represents a type of assignment source. Here’s a detailed list of the assignment source types:
|1||Software Catalog||The end user enabled the relationship by selecting the option in the AppCatalog Web page.|
|2||Administrator||An administrator created the relationship manually in the UI.|
|4||Usage Agent||The threshold of activity triggered a relationship to be created.|
|5||Device Management||The user/device were tied together during enrollment.|
|6||OSD||The user/device were tied together as part of OSD imaging.|
|7||Fast Install||The user/device were tied together temporarily to enable an on-demand install from the catalog if no UDA relationship installed before the Install was triggered.|
|8||Exchange Server connector||The device was provisioned through EAS.|
What this script does is that it evaluates all of the instances in the SMS_UserMachineRelationship class by the specified assignment source. It then outputs a custom PowerShell object showing what relationships have been created by the specified assignment source. As an extra feature, I’ve added a switch to the script that will allow you to remove the instances matching the assignment source you’ve specified. In environments where there’s a lot of devices, I’ve added the ShowProgress switch to the script that will give you an overview of the current progress of the script, so that you can determine for how long it may take to execute.
Download the script
I’ve made the script available for you to download it from the TechNet Gallery.
Using the script
In the case that you need to know what relationship have been assigned by the Usage Agent (created by the ConfigMgr client when enabled in Client Settings with the specified threshold settings), use the script like below:
1. Open an elevated PowerShell console and browse to where you’ve downloaded the script, e.g. C:\Scripts.
2. Run the following command:
.\Get-CMPrimaryUserAssignmentSource.ps1 -SiteServer CAS01 -AssignedBy UsageAgent -ShowProgress -Verbose
3. Once the script has successfully processed all of the targeted relationships, it will output each of them to the console.
If you wish to remove these relationships, simply just add the -Remove parameter and it will remove those instances. You can add the -WhatIf switch if you want to see what actions the script will perform before you remove the instances.
I hope this helps!