Users logged in to computers

I need to query a list of computers and retrieve users that have logged in to each computer.
for instance:
computerA =User1 logged in
ComputerB=User20 logged in

it will be nice if the script can give me for instance:
computerA= user1 ,user7,user3 have logged into at separate date and time..

Who is Participating?
Krzysztof PytkoConnect With a Mentor Senior Active Directory EngineerCommented:
Try to do that with free SysInternals tool called PsLoggedOn

This is really easy in use tool which allows for scripting

JoeIronsmithConnect With a Mentor Commented:

You can add this into your user's logon script:

@echo off
echo %date% %time% Logon %UserName% %ComputerName% >> \\MyServer\MyShare\LogTimes.txt

Then you can open it via excel (open a new file / Data / From text) and filter and sort it based on what information you need, e.g. username, computer name, etc.

SreRajConnect With a Mentor Commented:

You could try the following PowerShell script from Technet Script Gallery.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

jskfanAuthor Commented:
PsLoggedOn tool can be used to find current logged on user to which computer.

I need the last user logged on
jskfanAuthor Commented:
this is right link:

Set objWMIService = GetObject("winmgmts:\\Remotecomputername\root\cimv2")
 Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile")

For Each objItem in colItems
   Wscript.Echo objItem.Name
jskfanAuthor Commented:
Thank you Guys...The script I posted did the work
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.