How to find out if someone is logged on to remote computer

We manage a few hundred Windows 7 computers in a Windows domain. My IT team is not part of the central IT department so we are not domain admins but are local admins on the computers we manage by virtue of a global group in AD. Fairly often we need to RDP to a user's computer to do maintenance and it would be helpful if we didn't need to coordinate with the user to find a time when they are not logged in. Users log in to the domain on their computers when in their offices but may also connect from home via RDP. I have used the Sysinternals PSLoggedon command but this is a manual process and I'd like to be able to run a batch against a list of computers.

I see that the page below has both Powershell and what appears to be VBscript code but I don't know how to modify these to get the computer names from a text file and send the results to a CSV file.

http://serverfault.com/questions/32633/how-to-check-who-is-currently-logged-on-to-windows-workstation-from-command-line

Ideally I would like the output to go to a CSV file with the status next to each computer name, either "no user logged on" or "[username] local" or [username remote]

Something I have noticed is that even when I go to a machine and log on locally, sometimes when the task I'm doing requires a restart I see "another user is logged on. Do you want to restart?". We deploy Windows 7 Enterprise x-64 and I didn't think it supported user switching. When I came to the computer it didn't say "This computer is in use by [username] and locked". It just said "Press CTRL+ALT+DEL to log on" so I'm a little confused about how to tell if someone is logged in via user switching when looking at the machine locally. Hopefully the script I've described above can reveal this.

Thanks,
Don
donanderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
I would recommend using the Get-LoggedOnUser.ps1 script from the Microsoft Script Center.
https://gallery.technet.microsoft.com/scriptcenter/d46b1f3b-36a4-4a56-951b-e37815a2df0c

Will.
0
donanderAuthor Commented:
That script is bare bones and does not have the functionality I described. I'm sorry but I know virtually nothing about Powershell and unfortunately don't have the time to learn it.
0
NVITCommented:
Would the Qwinsta / QUERY SESSION commands work for you? You could do something like:

Make Clients.txt file of computer names:
client1
client2

Open in new window


Run psexec againsts those clients:
psexec @Clients.txt qwinsta

Open in new window

0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

donanderAuthor Commented:
I get:

'psexec' is not recognized as an internal or external command,
operable program or batch file.

I guess clients.txt, psexec and qwinsta all have to be in the same directory?

Sorry I'm clueless. You'll have to spell it out for me.
0
NVITCommented:
- psexec must be downloaded from Microsoft here: https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Extract it to a folder you use for utility programs. That folder may or may not be in the OS search PATH.

- For clients.txt, you would run notepad (or other text editor) and put your computer names in the file. One computer name per line.

- qwinsta is built-in to Windows

- psexec must be run as the domain admin.
0
donanderAuthor Commented:
"- psexec must be run as the domain admin."

In my original post I said "My IT team is not part of the central IT department so we are not domain admins..."

So psexec won't work.
0
NVITCommented:
> I have used the Sysinternals PSLoggedon command but this is a manual process and I'd like to be able to run a batch against a list of computers

If it works and you just want a batch version, you could pass the computer names in the list to psloggedon, like:

for /f %%a in (clients.txt) do psloggedon \\%%a

Open in new window


Or...

Not in CSV table format but may be usable:
set fnlog=psloggedon.txt
for /f %%a in (clients_text.txt) do (
  >> "%fnlog%" echo --------------------- %%a
  psloggedon -l \\%%a>> "%fnlog%"
)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
donanderAuthor Commented:
NewVillageIT (NVIT):

The 5 line script works. For most of the computers it said "Users logged on locally:" and gave a list of users which for most computers was one user. For one computer it said "No one is logged on locally." which is good because it is clear about no one being logged on locally.

My question is, will this show user(s) logged on remotely, via RDP?

Thanks,
Don
0
NVITCommented:
> ...will this show user(s) logged on remotely, via RDP?
Yes. RDC logons also show as local. If more than one RDC user is logged on, i.e. fast user switching, it shows each user name.

I do know it shows for a connection via Remote Desktop Connection dialog. But, I don't know the result if a user logs on via a web interface.
0
donanderAuthor Commented:
Ok. These are user workstations so no one would be logging on via a web interface.
0
donanderAuthor Commented:
The 5 line script does what I need.

Thanks much,
Don
0
NVITCommented:
You're welcome. I'm glad it worked out for you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

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.