Solved Run a script with psexec and report to text file

November 6, 2015 at 05:19:12
Specs: Windows 7
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%.txt

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.

message edited by Newbie0000


See More: Run a script with psexec and report to text file

Report •

✔ Best Answer
November 19, 2015 at 07:39:01
You know, if you're in a domain environment and your account has local admin access to the PCs, the easier method would be (untested):
for /f %%a in (c:\Folder\ComputerNames.txt) do (
  \\Server\Share\filever.exe "\\%%a\c$\Program Files (x86)\software.dll" | findstr "1.2.3.4" > NUL
  if not errorlevel 1 echo %%a %date% %time% Software Installed
)

How To Ask Questions The Smart Way



#1
November 6, 2015 at 05:29:59
Try removing the @
also, try %computername%.txt instead of just %computername%

EDIT: Scratch the above (maybe except the .txt part).
Started thinking normal batch
Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ


Report •

#2
November 6, 2015 at 05:34:29
Sorry I didn't put that in but I am using the %computername%.txt

Thanks.


Report •

#3
November 6, 2015 at 05:38:52
Sorry, screwed up my first post. I'm not too familiar with PsTools, however there are tons of documentation on it.

PsExec - TechNet

PsExec returns the "description" thing because you're not using the parameters correctly. Check the link above.

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ


Report •

Related Solutions

#4
November 6, 2015 at 05:43:58
Thanks, I have been to that site but I just can't seem to find what I need, thought I might have needed to use cscript but as far as I read that is to run VBScript and JScript I thinkg. I still working on it and hope to find a solution.

Thanks for the help.


Report •

#5
November 6, 2015 at 06:10:43
I came up with this, assuming the computer names are in Text.txt, and are stored in this manner:

Computername1
computername2
computername3
...

@Echo off
for /f "tokens=*" %%A in (C:\Folder\Text.txt) do (
	Echo Computer: %%A
	psexec \\%%A C:\Folder\Script.cmd >>Output_%%A.txt
)
pause > nul

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ


Report •

#6
November 6, 2015 at 06:46:55
As you are not specifying a username or password there needs to be a user on the remote computer with the same name and password as those that you use to log on to your computer. Is that the case?

Report •

#7
November 6, 2015 at 06:52:06
RainBawZ

Thanks for some reason it says it can't find the file but I have triple checked and it's test and spelling is correct, the path is C:\~Scripts\SWName 10.1.55.7894\Text.txt, maybe the ! or spaced is doing something?

ijack
I am logged in as admin on the source computer and the target computers will have users logged into them.


Report •

#8
November 6, 2015 at 07:53:47
Try replacing the ~ with ^~
Also try enclosing the path in quotes

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ


Report •

#9
November 6, 2015 at 08:18:33
Does the Admin account on the remote computers have the same password as on your computer? If not then what you are trying to do will not work. I'm sure that you can see that it would be a tremendous security hole if logging on as Admin on one computer automatically gave you Admin rights on another computer. Whatever you may think about Microsoft's security they are not that stupid.

Report •

#10
November 6, 2015 at 11:54:19
Is Active Directory involved? If so, maybe you want to take your script to Group Policy. If not, tack on 2>&1 to the end of your command, so that you can grab the errors as well.

How To Ask Questions The Smart Way


Report •

#11
November 12, 2015 at 05:36:41
Hi, sorry I was off all week but am back at it.

ijack, yes I am using an admin account to log in and run the script and it is a domain admin password so that part should be ok.

I will work on it more and keep you updated.


Report •

#12
November 19, 2015 at 06:15:04
Sorry I was away again.

This is a script that works for what I want:

"\\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

I need to parse through a text file with computer names to run it on each computer in the text file.

I tried:

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

I also tried:

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?


Report •

#13
November 19, 2015 at 07:39:01
✔ Best Answer
You know, if you're in a domain environment and your account has local admin access to the PCs, the easier method would be (untested):
for /f %%a in (c:\Folder\ComputerNames.txt) do (
  \\Server\Share\filever.exe "\\%%a\c$\Program Files (x86)\software.dll" | findstr "1.2.3.4" > NUL
  if not errorlevel 1 echo %%a %date% %time% Software Installed
)

How To Ask Questions The Smart Way


Report •

#14
November 19, 2015 at 07:49:28
That's great, thanks. I tried something like that but yours makes more sense, I will give it a try and get back to you.

Thanks again for the quick response.


Report •

#15
November 24, 2015 at 10:24:45
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


Report •

#16
November 24, 2015 at 17:33:46
Well, you've got a REM stuck in the front. Also "if %errorlevel% EQU 0" is incorrect. You need to stick closer to what's shown above.

How To Ask Questions The Smart Way


Report •

#17
November 25, 2015 at 03:50:54
Yes I have REM in front to test the rest of the script that works fine, as I stated. If errorlevel EQU 0 then there is no error and it does as it should in the script?

Report •

#18
November 26, 2015 at 05:09:20
Your IF statement only works if it's not in a loop. That's because %ERRORLEVEL% is evaluated once, just before the loop starts. You either need to use delayed expansion, so !ERRORLEVEL! is evaluated every time the loop hits your IF statement, or you need to use IF NOT ERRORLEVEL 1.

How To Ask Questions The Smart Way


Report •

#19
December 12, 2015 at 03:17:12
Thank you for the help, I am looking through computer names in a text file to check each computer for a certain string that will tell me if the software I sent out via GPO was installed successfully and put the outcome in a file called Report. I found something that worked for me:

@ECHO OFF
FOR F "usebackq tokens=*" @@a IN ("c:\Folder\ComputerNames.txt") DO (
"\\Server\Share\filever.exe" "\\@@a\C$\Program Files\File.dll" | findstr "1.2.3.4"
&& echo @@a %date% %time% Software Installed >> "C:\Folder\Report.txt"


Report •

Ask Question