Run a script with psexec and report to text file

I am trying to run a script on the list of computer in a text file and I am missing something. I have just started using PSTools and am very new to scripting.

psexec @C:\Folder\Text.txt C:\Folder\Script.cmd >> C:\Folder\%computername%

Not sure if I have to use a run command or what is wrong with my file. I don't really get any error just this:

PsExec v1.98 - Execute processes remotely
Copyright (C)....
Sysinternals - .......

Thanks in advance for the help.
Newbie0000Asked:
Who is Participating?

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

x
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.

Muhammad BurhanManager I.T.Commented:
Newbie0000Author Commented:
Thanks, I've been looking there and hope to have it sorted out soon. Trial and error as I go! ;)
FOXActive Directory/Exchange EngineerCommented:
Try this :
psexec @C:\Folder\Text.txt command C:\Folder\Script.cmd >> C:\Folder\%computername%
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

NVITEnd-user supportCommented:
psexec @C:\Folder\Text.txt cmd /c C:\Folder\Script.cmd >> C:\Folder\%%computername%%

Note: I also changed %computername% to %%computername%%

I think what you are trying to do is put all computername into one file? If so, have to change things.
FOXActive Directory/Exchange EngineerCommented:
Revised
psexec @C:\Folder\Text.txt command -c -f C:\Folder\Script.cmd >> C:\Folder\%computername%
Newbie0000Author Commented:
Thanks but still no luck. Maybe I don't have to use psexec? I just want to run this script over the network OR have it run on computers in a text file and report back to a text file?? I'm also looking at other options.
NVITEnd-user supportCommented:
You have to use the -c switch to copy script.cmd over.
psexec @C:\Folder\Text.txt -c C:\Folder\Script.cmd cmd /c Script.cmd >> C:\Folder\results.txt

Open in new window


Here's a solution that finds outlook .PST files on clients. It puts the computername also.
psexec @stns.txt cmd /c "echo %%computername%% -------------- & dir /s "c:\users\*.pst"" >> c:\folder\pstfiles.txt

Open in new window


What does your script.cmd do?
FOXActive Directory/Exchange EngineerCommented:
Newbie,
You may have to add your username and password to run the batch file remotely on the machines...

psexec @C:\Folder\Text.txt -c -f C:\Folder\Script.cmd - u domain\username -p yourpassword >> C:\Folder\%computername%\report.txt

**If you don't add the -p with your password it will prompt you to enter your password which will be hidden.   The option is yours***
Newbie0000Author Commented:
The script looks for a sting for software I pushed out via GPO and reports back with the computer in a text file, here is the script I used, it works but I just need to either send it to all on the network or send it to computer names in a text file.

"\\Server\Share\filever.exe "C:\Program Files (x86)\software.dll" |findstr "1.2.3.4"
if %errorlevel% EQU 0 (
     echo %computername% %date% %time% Software Installed >> "\\Server\Share\%computername%.txt
     goto:eof
)
eof
FOXActive Directory/Exchange EngineerCommented:
Very good, try the last command I sent you using the - u and - p for your domain credentials.
NVITEnd-user supportCommented:
This works:
psexec @C:\Folder\Text.txt -c -f C:\Folder\Script.cmd - u domain\username -p yourpassword cmd /c Script.cmd

Open in new window


With your code, you do know you will end up with separate filenames, each computer1.txt, computer2.txt, etc.?
Newbie0000Author Commented:
Hi, sorry I had to be away.

Would this work? It will check every computer name in the text file for the string and report back to another text file? No sure I am sure the correct 'command to run' in the For /F statement after do, maybe I should use RUN and not START???

for /f "tokens=*" %%j in (C:\folder\file.txt) do (START "" \\Server\Share\filever.exe" "C:\Program Files (x86)\Microsoft Office\x\file.dll" |findstr "x.x.x.x"
if %errorlevel% EQU 0 (
      echo %computername% %date% %time% Software Installed >> "\\Server\Share\Software.txt")
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That does not make any sense. START does not run a script or application remotely. You also never refer to the %%j value of the loop.

What about what NVIT posted in http:#a41199665 ?
FOXActive Directory/Exchange EngineerCommented:
This below command should work and give you a report.  Let us know exactly what you are trying to accomplish

psexec @C:\Folder\Text.txt -c -f C:\Folder\Script.cmd - u domain\username -p yourpassword >> C:\Folder\\report.txt
Newbie0000Author Commented:
Thanks, I'm very new to scripting and I had some issues with the other one but I will work on it again.
Newbie0000Author Commented:
That won't work for me and it doesn't give me any error. I ran this script on a pc and it worked so I know my script is fine:

"\\Server\Share\filever.exe "C:\Program Files (x86)\software.dll" |findstr "1.2.3.4"
if %errorlevel% EQU 0 (
     echo %computername% %date% %time% Software Installed >> "\\Server\Share\%computername%.txt
     goto:eof
)
eof

So I put the psexec in a *.cmd file and tried to run it from the command line:

psexec @c:\Folder\ComputerNames.txt -c -f c:\folder\scriptabove.cmd -u domain\administrator -p password cmd /c scriptabove.cmd

I also tried as was suggested:

psexec @c:\Folder\ComputerNames.txt -c -f c:\folder\scriptabove.cmd -u domain\administrator -p password >> C:\Folder\report.txt

I have the script that works in it's own file "scriptabove.cmd"

I tried to put \\domain\administrator as well but I'm not sure what the issue is as I don't get any error?
NVITEnd-user supportCommented:
This works...

Move the -u and -p switches to the front as in...
psexec @c:\Folder\ComputerNames.txt -u domain\administrator -p password -c -f c:\folder\scriptabove.cmd cmd /c scriptabove.cmd

Open in new window

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Newbie0000,

The first line of your script,
"\\Server\Share\filever.exe "C:\Program Files (x86)\software.dll" |findstr "1.2.3.4"

Open in new window

is wrong, even if it should seem to run fine. Remove the unneeded leading double quote to make it correct. This can have arbitrary effects, and might be an issue besides the proper usage of psexec.


NVIT,

-f does not have a parameter. In fact you are running this line remotely:
c:\windows\system32\scriptabove.cmd cmd /c scriptabove.cmd

Open in new window

It works, though being wrong.
NVITEnd-user supportCommented:
Thanks for catching that, Qlemo.
Newbie0000Author Commented:
OK, I thought I could do it this way but I have an error with the FOR /F syntax in the first line, if I REM out the first line the script works??

REM for /f "tokens=*" %%a in (C:\Folder\Computerlist.txt) do (
     "\\Server\Share\filever.exe" "C:\Program Files\File.dll" |findstr "x.x.x.x"
if %errorlevel% EQU 0 (
    echo %computername% %date% %time% Software Installed >> "C:\Folder\Report.txt"
     goto:eof
)
eof

So I am doing something wrong in the first line of the file, is doesn't do anything, it should go through the Computerlist.txt file with and check each computer name in the list for the dll
NVITEnd-user supportCommented:
I think you had it right the first time using psexec at ID: 41275589. Did you try that?

I think in your latest here, you want to run filever.exe against each machine, right? But, that's what's psexec is for.
Newbie0000Author Commented:
I guess I just gave up with psexec, I couldn't get it to work, let me try it again.
Newbie0000Author Commented:
Thanks for all you help on this, I found something that works for me:

@ECHO OFF
FOR /f "usebackq tokens=*" %%a IN ("C:\Folder\computernames.txt") DO (
     "\\Server\Share\filever.exe" "\\@@a\C$\Program Files (x86)\software.dll" | findstr "1.2.3.4" && echo %%a %date% %time% Software Installed >> "\\Server\Share\%computername%.txt
)

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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
There are lot of issues:

1. The posted solution is wrong - @@ needs to be %%.
2. It is restricted to work against 64bit OS only, because you hard-coded "C$\Program Files (x86)".
3. You should use
      findstr "1.2.3.4" > nul
   to suppress the (unwanted) output of that command.
4. You log into  "\\Server\Share\%computername%.txt
    (a) that is missing the closing double quote,
    (b) it logs into a file named after the executing machine, which does not make sense, as it will not change, and does not matter either

Next: You seem to have chosen arbitrary comments, which are not related to your self-found solution. Remember you should not assign points just for effort, but accepted answers should always be directly related to the solution.
Newbie0000Author Commented:
I am very new to scripting and with all your help I was able to come up with this solution, thank you for all your help.
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.