SCCM – Find system by Last Logged on User Query

sccm logo

Last updated on April 16th, 2023 at 11:25 pm

Read Time:1 Minute, 59 Second

If you need to find a machine for a particular user in your business using SCCM, one way you can do it is to use a custom query to find the machine that relates to the last logged on user.

This means that you can run this query, it’ll prompt for a username, enter the username and it’ll then bring back the computer of which the entered username last logged into.

The query below is the full code to bring back all sorts of information, you can strip this right back if you like to just bring back simple information like username and machine name…

If you wish to view just a list of last logged on users and then be able to search on that information, a slightly amended version of this code is available here:

Last logged on user query – All Systems

There is also a query that you can use that will prompt for a NetBIOS name and supply you with all the information you require:

Find last logged on user by NetBIOS name

The query code to do this is below:

select   
 SMS_R_System.LastLogonUserName,  
 SMS_R_System.Name,  
 SMS_R_System.SMSAssignedSites,  
 SMS_R_System.Client,  
 SMS_R_System.IPAddresses,  
 SMS_R_System.IPSubnets,  
 SMS_R_System.MACAddresses,  
 SMS_R_System.OperatingSystemNameandVersion,  
 SMS_R_System.ResourceDomainORWorkgroup,  
 SMS_R_System.LastLogonUserDomain,  
 SMS_R_System.AgentName,  
 SMS_R_System.AgentSite,  
 SMS_R_System.AgentTime,  
 SMS_R_System.SNMPCommunityName,  
 SMS_R_System.SystemRoles,  
 SMS_R_System.SMSUniqueIdentifier,  
 SMS_R_System.ResourceId,  
 SMS_R_System.ResourceNames,  
 SMS_R_System.ResourceType,  
 SMS_R_System.NetbiosName  
 from  
 SMS_R_System  
 where  
 SMS_R_System.LastLogonUserName = ##PRM:SMS_R_System.LastLogonUserName##

Creating the SSRS Report

We have now created a guide that will help you to create your SSRS reports based on the data that this guide will pull into the Configuration Manager database.

You can access this guide by clicking the link below:

Create a SSRS Report using Configuration Manager Database Data

More Queries

Our full range of SQL and WQL Collection queries are available here.

Feedback

If you have any questions or feedback about this post, or if you would like us to create any queries for you, please go ahead and leave us a message below in the comments section and we will get back to you as quick as we can.

Click to rate this post!
[Total: 1 Average: 5]

Free Subscription

If you want to be notified when we post more quality guides like this one, sign up to our free subscription service and you will receive an email when a new post is live.

Join 441 other subscribers.

No need to worry, we will not be filling your inbox with spam and you can unsubscribe anytime you like.


Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.