Find My Sessions / Logins

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
cls
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"
cls
echo Done!

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

2nd attempt

@echo off
cls
echo Finding My Logins
echo === %date% at %time% ===>>"FML.log"
for /f %%i in (Servers-all.txt) do psloggedon -l \\%%i  >>FML.log
cls
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.

TIA!
GHoggeAsked:
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.

BeartlaoiCommented:
Based on your first attempt I added recursion to echo the servername into the file.
@echo off
if "%2" == "DOONE" goto DOONE
cls
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
cls
echo Done!
goto :EOF

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

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
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
IT Administration

From novice to tech pro — start learning today.