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.
3 User Unused/deprecated.
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

135_1

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!

Nickolaj Andersen
Principal Consultant and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Currently working for TrueSec as a Principal Consultant. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences and user groups.

(3640)

comments
  • Emil Skibsted
    Posted at 11:21 November 2, 2015
    Emil Skibsted
    Reply
    Author

    Hi,

    Is there a way to get a list of user that do NOT have any Primary Device assigned?

  • Mark Mijnders
    Posted at 12:04 May 23, 2016
    Mark Mijnders
    Reply
    Author

    Or is there a way to get the PrimaryUserName in a column in the SCCM console 🙂

    Thanks anyway for this script!

    • Nickolaj
      Posted at 18:10 May 23, 2016
      Nickolaj
      Reply
      Author

      Hi Mark,

      Not that I know of, but why not submit that as feedback using the User Voice site. Perhaps they can extend the console to include that feature in a future release!

      Regards,
      Nickolaj

      • Emil Skibsted Kristensen
        Posted at 11:04 September 21, 2016
        Emil Skibsted Kristensen
        Reply
        Author

        Hi again,

        I am using this report to find users with no prim. device.

        “Device Affinity Associations Per Collection”

        • Jody
          Posted at 19:14 October 7, 2016
          Jody
          Reply
          Author

          Hello,

          Thanks for posting this. I’m wondering if you can elaborate? I too would like this report. Are you modifying the .ps1?

          • Emil Skibsted Kristensen
            Posted at 12:17 October 13, 2016
            Emil Skibsted Kristensen
            Author

            It is not related to the script. It is a build in report in SCCM (Current Branch)

  • machoud
    Posted at 17:09 July 10, 2016
    machoud
    Reply
    Author

    Great Script!!!!

  • Eden Oliveira
    Posted at 19:56 September 28, 2016
    Eden Oliveira
    Reply
    Author

    One more time, very well done, Nickolaj.

    Good job! Thank you for this script.

    Eden Oliveira

  • Mike Ga
    Posted at 18:02 October 22, 2016
    Mike Ga
    Reply
    Author

    why do this? theres a report that does this already…

    • Nickolaj
      Posted at 15:09 October 23, 2016
      Nickolaj
      Reply
      Author

      Hi Mike,

      There are several other ways of working with ConfigMgr and crunch the data it holds than just using the built-in tools. This post was meant to provide an alternative to the reports available in the product.

      Regards,
      Nickolaj

  • Guest
    Posted at 10:02 November 15, 2016
    Guest
    Reply
    Author

    is there any way to get the Primary user secific machine?

  • Kevin K
    Posted at 00:22 April 26, 2017
    Kevin K
    Reply
    Author

    I’m a PowerShell noob. Is there an easy way to also output the results to a .CSV file, without (or with) modifying the script?

    • Maurice Daly
      Posted at 10:06 April 26, 2017
      Maurice Daly
      Reply
      Author

      Hi Kevin,

      All you need to do is pipeline the command through and use the Export-CSV cmdlet. Example;

      .\Get-CMPrimaryUserAssignmentSource.ps1 -SiteServer YOURSITESERVER -AssignedBy UsageAgent | Export-CSV -Path PATHTOFILE\FILENAME.CSV -NoTypeInformation

      Maurice

  • Leave a Reply