Find My Sessions / Logins

Posted on 2013-09-26
Medium Priority
Last Modified: 2013-09-27
I am trying to create a batch file that will search through a list of servers provided in a text file, look for my sessions and output to a text file.  A plus would be for it to actually log me off of any servers where I have a session.

Here are my attempts.

1st Attempt

@echo off
echo Finding My Sessions
echo === %date% at %time% ===>>"FMS report for %1.log"
for /f %%i in (Servers.txt) do qwinsta %1 /server:%%i >>"FMS report for %1.log"
echo Done!

Would have been good, but qwinsta does not provide the server name.

2nd attempt

@echo off
echo Finding My Logins
echo === %date% at %time% ===>>"FML.log"
for /f %%i in (Servers-all.txt) do psloggedon -l \\%%i  >>FML.log
echo Done!

This kind of works, but requires me to search the output and manually log myself off of the servers.

I would prefer this work without the use of any scripting languages.

Question by:GHogge
1 Comment

Accepted Solution

Beartlaoi earned 2000 total points
ID: 39529179
Based on your first attempt I added recursion to echo the servername into the file.
@echo off
if "%2" == "DOONE" goto DOONE
echo Finding My Sessions
echo === %date% at %time% ===>>"FMS report for %1.log"
for /f %%i in (Servers.txt) do call %0 %1 DOONE %%i
echo Done!
goto :EOF

echo %3 >>"FMS report for %1.log"
qwinsta %1 /server:%3 >>"FMS report for %1.log"

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

The Internet has made sending and receiving information online a breeze. But there is also the threat of unauthorized viewing, data tampering, and phoney messages. Surprisingly, a lot of business owners do not fully understand how to use security t…
When it comes to a career in IT service management, there are a few necessary learning blocks along the way. ITIL Foundation is one of them. Here's why.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question