First published on TechNet on Jul 12, 2016
Hi again, this is Stephen Mathews and I'm here to talk about how to determine the dominant or primary user of a Windows operating system. This insight can help administrators facilitate direct communication with the affected user when a system needs management, and can even help non-enterprise users, such as a parent questioning which child is using their computer the most. We'll consider the different types of login data available, show how to expose it in the various OS instruments, and then use that information to update the system's Active Directory computer object 'ManagedBy' attribute. This post uses PowerShell Version 5 on Windows 10 to illustrate examples and it references settings that may not exist in legacy OS versions. All code examples are for illustration purposes only and should be thoroughly tested in a non-production environment. This post is intended to be used within a client OS using its built-in capabilities. Additionally, it is written from an Asset Tracking perspective and is not directly addressing Security and/or User Auditing concerns. What type of information are you after? Are you looking for the currently logged in user on the console, remotely logged in users, the last logged in user, the dominant user, or a list of all users? How will the information be used: for real-time troubleshooting, historical reference, or external app consumption? Will you script a solution, if so where will you output the data? Will the script be run manually or automatically, if automatically will you use a startup or login script, or a scheduled task? File System The filesystem can be the quickest and most efficient way to determine the regular users of a system. By expanding the 'UserProfile' environmental variable's parent directory, you can see users that have had a profile created on that machine. You can check these profile directories and see the Created, Accessed, Modified, and Written timestamps for all of the systems' users. Unfortunately, this can also be the most misleading. The user profile directories are mapped via a Security Identifier (SID) that is stored in the registry. If a user account's logon name is changed, they will still map to the original folder name. Also, if a user's profile is corrupted they may not get a local directory and be redirected to the default profile. Additionally, the timestamps may not be updating depending on your OS version and/or auditing settings for those folders. And finally, you may not have rights to see the folders or their attributes.
Registry The registry contains all the configurations and settings for the OS. There are multiple locations in the registry to find specific information about the users. User accounts are usually stored as SIDs inside the registry and will need to be converted into account names.
The registry is a sensitive part of the OS and can be corrupted. This risk of corruption leads many organizations to strictly limit and audit registry access. Certain registry settings may change only during startup and/or login, meaning the data may be stale while it's being queried.
WMI Windows Management Instrumentation is an infrastructure that exposes the OS to management. You can find current configuration settings, then get and set those properties. WMI queries can be difficult to construct and may be resource intensive to the point of resource exhaustion. Take precautions to test the retrieving and setting of WMI components in a test environment before using inside production. Access to WMI may be restricted and audited for the same reasons as the registry.
ADSystemInfo This is an overlooked tool to identify current system Active Directory network settings. The 'UserName' property will report the currently logged in user. It requires network connectivity to return settings and there's no inherent way to run it remotely.
Event Logs Event logs are the record keepers of all activities on the system. As such they are the definitive source for tracking the login process. Logging can be turned on or off per provider and the logging level can be tailored based upon the event type: Critical, Error, Warning, Information, and Verbose. The 'UserID' property is typically set to the SID of the account creating the event, this is automatically translated for you in the Event Viewer. If the individual Event Log does not populate the 'UserID' property, you can parse the event message text with a SID to find events.
The event log filter can be difficult to configure and a poorly created filter may be resource intensive to the point of resource exhaustion. Access to certain logs may be restricted and not all event logs record the same information in their properties. Furthermore, the logs may be collected into a central repository, making them unavailable or lacking significant detail to make an accurate determination. In the first example it uses the Group Policy Operational log and groups the events by 'UserID', the second example events do not populate the 'UserID' property and need the message data to be parsed for matching SIDs; the list of SIDs were defined from the Win32_UserProfiles class.
System Center Configuration Manager For those of you with SCCM, it does the hard work for you in its Asset Intelligence feature set. Click to read more about the SMS_SystemConsoleUser Client WMI Class that calculates the dominant user for you. Here are a couple of screen shots. Using the information In this example, we want to update the Active Directory computer object 'ManagedBy' attribute with the dominant user. In order for this to happen we have to edit the default permissions to that attribute in the Organizational Unit where the computer object resides. Step two utilizes a script to perform the update, there are easier ways to do this, however we want to utilize a process that is as intrinsic as possible to the OS.
In closing, I hope this explains the different types of login information that can be collected, exposes those information locations for you to use, and inspires you to keep track of your assets. A special thanks to Mike Kanofsky who created the script and found the permissions required to update the 'ManagedBy' computer object attribute and to Kevin Kasalonis for his SCCM expertise. Thanks for reading! References: SMS_SystemConsoleUser Client WMI Class https://msdn.microsoft.com/en-us/library/cc143513.aspx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.