psexec

I have a list of servers @servers.txt I want to run
 openfiles /query /fo csv /NH /v and out put the open files to the same place \\server\share\openfilesonervers.csv or txt

tried 》》\\server\share\openfiles.txt

nothing is working

need to capture all openfiles
not shares. but files in the share and log user name
LVL 5
IndyrbAsked:
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.

oBdACommented:
No need for psexec; openfiles can run remotely. Try if the following works for you:
@echo off
setlocal
set LogFile=\\server\share\openfilesonervers.csv
for %%a in ('type servers.txt') do (
	openfiles.exe /query /s %%a /fo csv /NH /v >>"%LogFile%"
)

Open in new window

0
IndyrbAuthor Commented:
didn't work, file is blank.. do I need to give it the local path?  or use -I -h -u username - p password
0
oBdACommented:
Path can be whatever you can access with the account running the script.
Were there error messages?
Just in case: do not start it with a double-click from Explorer; open an elevated command prompt, "cd" into to the script folder, and start the script from there.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

IndyrbAuthor Commented:
no netwoprk provider given the path..

but it works when I use openfiles command by itself

and yes running via cmd prompt
there is just to many to write out command for every server
0
oBdACommented:
Then the path to the log file seems to be incorrect. Try a local path on the machine you're running the script on.
0
IndyrbAuthor Commented:
same:

ERROR: No network provider accepted the given network path.
ERROR: No network provider accepted the given network path.



@echo off
setlocal
set LogFile=F:\OpenSessionsReport\openfilesonervers.csv
for %%a in ('type servers.txt') do (
	openfiles.exe /query /s %%a /fo csv /NH /v >>"%LogFile%"
)

Open in new window

0
oBdACommented:
Sorry, my bad.
@echo off
setlocal
set LogFile=F:\OpenSessionsReport\openfilesonervers.csv
for /f %%a in ('type servers.txt') do (
	openfiles.exe /query /s %%a /fo csv /NH /v >>"%LogFile%"
)

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
IndyrbAuthor Commented:
What did you change?
0
IndyrbAuthor Commented:
Then how do I run on a task every hour
0
oBdACommented:
Added /f after "for" in line 4.
You just create a task and set its trigger properties to run daily, repeating it every hour for one day.
See for example here for details: http://stackoverflow.com/questions/4249542/windows-scheduler-to-run-a-task-every-x-minutes
0
IndyrbAuthor Commented:
Thanks for your help oBdA... one quick question... Is there a way to have each server go to a separate logfile like server1_logfile1` for each server in servers.txt

My log file or csv is 180MB and too much for excel to do anything with it.
So I probably need to break out in smaller chunks.
0
oBdACommented:
No problem; inside the for loop, %%a will contain the name of the machine currently being processed:
@echo off
setlocal
for /f %%a in ('type servers.txt') do (
	openfiles.exe /query /s %%a /fo csv /NH /v >>"F:\OpenSessionsReport\openfilesonserver_%%a.csv"
)

Open in new window

0
IndyrbAuthor Commented:
Do you know much about excel macros where you can inport each on - remove so of the fields, and add columns, and sort by XYZ then XYZ then filter by unique records? is there a script?
0
oBdACommented:
If you want to further process the output of openfiles, it's probably easier in Powershell than in VBA.
Just post a question in http://www.experts-exchange.com/topics/powershell/ and describe how you want the output to be processed.
Feel free to add a link here; if I have time, I'll have a look.
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
Windows Batch

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.