Skip to content
SCCM Primary Last Logon User Report | SQL Query |   ConfigMgr

SCCM Primary Last Logon User Report | SQL Query | ConfigMgr

Written By Debabrata Pati
Last Updated August 28, 2024
Posted In SCCM
SHARE

Today, I will discuss SCCM Primary Last Logon User Report | SQL Query |ConfigMgr. Are you looking for the SCCM Primary Last Logon user Report? If so, you are in the correct place.

This post will discuss how to find primary user information and last login information from the SQL query. You may need this report if someone asks about it in your organization.

I have seen this question pop up in the forums and other communities. I believe this report may help most SCCM admins.

I recommend looking at the ConfigMgr SCCM List of Default Reports to get more details about out-of-box reports.

Patch My PC

What is SCCM Primary User?

The SCCM Primary User is the user assigned to a particular device and the method by which each user-device relationship was assigned.

What is SCCM, Last Logon User?

As the name suggests, the last logon user is the last user who logged into the device for a significant amount of time.

What is SCCM Currently Logged on User?

The currently logged-on user to the ConfigMgr or SCCM-managed device. This is the almost live data of the logged-on users.

Pre-requisite – SCCM Primary Last Logon User Report

If you need Primary user details from SCCM, you just need to enable user discovery from the ConfigMgr console. You can also get the Last login user information from system discovery. Let’s see the SQL query below to get such information.

SQL Query – SCCM Primary Last Logon User Report

Now, it’s time to find the SQL query for the SCCM Primary Last Logon user Report. Follow the steps mentioned below.

  • Open the SQL Management Studio from the SQL box.
  • Connect your Database Engine.
  • Right Click on your database CM_XXX and click on ‘New Query’
  • Please copy the following SQL query to find the report of Primary User information as well as the Last login user information with their respective email ID
  • Click on the Execute button.
Select VRS.Netbios_Name0 as 'Machine Name', VUMR.UniqueUserName as 'Primary User', VRS,User_Name0 as 'Last Logon User',
VRU.Mail0 as 'Primary User Email', VRU1.mail0 as 'Last Logon User Email'
from V_R_System VRS
left join v_UserMachineRelationship VUMR on VRS.ResourceID=VUMR.MachineResourceID
left join V_R_User VRU on VRU.Unique_User_Name0=VUMR.UniqueUserName
join v_R_User VRU1 on VRU1.User_Name0=VRS.User_Name0
SCCM Primary Last Logon User Report | SQL Query |   ConfigMgr - Fig.2
SCCM Primary Last Logon User Report | SQL Query | ConfigMgr – Fig.2

Resources

  • Last-Logon-Timestamp attribute
  • Currently Logged on User – Tool – PsLoggedOn v1.35

We are on WhatsApp. To get the latest step-by-step guides and news updates, Join our Channel. Click here –HTMD WhatsApp.

Author

Anoop C Nair has been Microsoft MVP for 10 consecutive years from 2015 onwards. He is a Workplace Solution Architect with more than 22+ years of experience in Workplace technologies. He is a Blogger, Speaker, and Local User Group Community leader. His primary focus is on Device Management technologies like SCCM and Intune. He writes about technologies like Intune, SCCM, Windows, Cloud PC, Windows, Entra, Microsoft Security, Career, etc.

Written by

Debabrata Pati has more than 8+ years of experience in IT. Skilled in MEMCM, Azure, and Powershell. More than Six (6) years of experience in MEMCM (SCCM) administration, OSD, and Troubleshooting for the environment with more than 100K client devices.

Discussion · 5 comments

  1. dont understand why the usermachinerelationship view doesnt have a the userid included so the user view can just be joined on that and not the user name.

  2. left join v_FullCollectionMembership fcm on VRS.resourceid=fcm.resourceid
    where fcm.CollectionID = ‘SMS00001’

  3. Hello Prajwal ,
    Tried to run the above query but it gave me errors :

    Msg 207, Level 16, State 1, Line 1
    Invalid column name ‘VRS’.
    Msg 209, Level 16, State 1, Line 1
    Ambiguous column name ‘User_Name0’.

Join the discussion

Your email address will not be published. Required fields are marked *

Related guides

Intune

Windows 11 KB5101650 KB5099414 July 2026 Patch and 3 Zero Day Vulnerabilities and 570 Flaws

Key Takeaways Windows 11 KB5101650 KB5099414 July 2026 Patch and 3 Zero Day Vulnerabilities and 570 Flaws! In the July 2026 Patch, Microsoft introduced new features designed to improve the overall Windows experience. The update adds enhancements to Windows Update for more flexible update management and introduces Point-in-Time Restore, providing an additional recovery option for […]

AC Anoop C Nair 9 min read
Intune

2026 June KB5094126 KB5093998 Windows 11 Patch | 3 Zero Day Vulnerabilities and 200 Flaws

Key Takeaways 2026 June KB5094126 KB5093998 Windows 11 Patch | 3 Zero Day Vulnerabilities and 200 Flaws! The June 2026 Windows 11 Patch Tuesday update brings several improvements to File Explorer. It adds support for additional archive formats, including UU, CPIO, XAR, and NuGet Packages (NUPKG). The update also preserves View and Sort preferences in […]

AC Anoop C Nair 10 min read
Intune

2026 May KB5089549 KB5087420 Windows 11 Patch | 0 Zero Day Vulnerabilities and 120 Flaws

Key Takeaways The Windows 11 May 2026 Patch KB5089549 KB5087420 Update brings important security fixes, performance improvements, and reliability enhancements across the operating system. The update introduces new features such as Xbox Mode for gaming, File Explorer improvements, enhanced input and sharing experiences, better taskbar and Windows Hello reliability, and additional enterprise management capabilities for […]

AC Anoop C Nair 8 min read
SCCM

ConfigMgr 2603 Introduces New Early Update Enrollment Process

Key Takeaways In this post we are discussing the ConfigMgr 2603 Introduces New Early Update Enrollment Process. Microsoft has officially released Configuration Manager version 2603 to the Early Update Ring, giving organizations an opportunity to test upcoming improvements before the global production rollout. The release is targeted at enterprises running ConfigMgr version 2409 or later […]

AC Anoop C Nair 3 min read