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.

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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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.
NVITEnd-user supportCommented:
Would the Qwinsta / QUERY SESSION commands work for you? You could do something like:

Make Clients.txt file of computer names:

Open in new window

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

Open in new window

SD-WAN: Making It Work for You

As bandwidth requirements and Internet costs grow, businesses naturally want to manage budgets by reducing reliance on their most expensive connection types. Learn more about how to make SD-WAN work for your business in our on-demand webinar!

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.
NVITEnd-user supportCommented:
- psexec must be downloaded from Microsoft here:
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.
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.
NVITEnd-user supportCommented:
> 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


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

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?

NVITEnd-user supportCommented:
> ...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.
donanderAuthor Commented:
Ok. These are user workstations so no one would be logging on via a web interface.
donanderAuthor Commented:
The 5 line script does what I need.

Thanks much,
NVITEnd-user supportCommented:
You're welcome. I'm glad it worked out for you.
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.