Powershell – How to generate a report of the last time each domain user logged in to a specific windows server 2008 vm

active-directorypowershellwindows-server-2008

I have a Windows server 2008 R2 vm that has roughly 4800 domain users that have logged in over the last 3 years. Id like to generate a report that list the users names along with the last time they logged in to this particular vm.

Everything I come across through searching is either the last user to log in to a vm or the last log in time of users across a domain. I can't find a way to generate a list of the usernames and the last time they logged in to the specific vm.

Any help?

Best Answer

If the logs do not go back far enough, you can also find this in the Win32_UserProfile class in WMI.

This PowerShell should get you started:

Get-WmiObject Win32_UserProfile | Select-Object LocalPath,LastUseTime | Sort-Object LastUseTime