How to run mutliple commands with psexec ?

Asgorath

[H]ard|Gawd
Joined
Jul 12, 2004
Messages
1,253
I want to run a script that will search all the computers on my network for common spyware, chat programs, and other baddies that we don't want our users to have. I am looking to make a psexec script that will search for directories on their computers and look for a positive match.

For example:

psexec @c:\computers.txt cmd /c dir "c:\program files"\MyWebSearch

Would return with error code 0 if that directory existed. Otherwise it would return with error code 1.

Note: the argument c:\computers.txt is a list of all the computers on my domain that I want to check.

So if I make up a batch file like so:

Code:
psexec @c:\computers.txt cmd /c dir "c:\program files"\MyWebSearch
psexec @c:\computers.txt cmd /c dir "c:\program files"\AOL*
psexec @c:\computers.txt cmd /c dir "c:\program files"\AIM*
psexec @c:\computers.txt cmd /c dir "c:\program files"\yahoo*
psexec @c:\computers.txt cmd /c dir "c:\program files"\trill*

this would give me output like so for each of the commands for each of the computers:

--Positive Match
Volume in drive C has no label.
Volume Serial Number is CCD0-6CA7

Directory of c:\program files\MyWebSearch

04/06/2007 09:50a <DIR> .
04/06/2007 09:50a <DIR> ..
05/14/2007 10:48a <DIR> bar
04/06/2007 09:50a <DIR> SrchAstt
0 File(s) 0 bytes
4 Dir(s) 75,186,749,440 bytes free
Volume in drive C has no label.
Volume Serial Number is 9839-31AC
--Negative Match
Volume in drive C has no label.
Volume Serial Number is 9839-31AC

Directory of c:\program files

Now the question is, how can I run multiple commands on each computer in a row. That way I can see what computer I'm running it on with something like an ipconfig command. Then I can search for each directory on that computer. Then move on to the next computer.

Any ideas are welcome
thanks.
 
Change it so that your batch file, instead of psexec, provides the system name from the file with a FOR loop.

That would be what I would do if I was going to do it.

Here is an example:


Code:
for /f %%i in (servers.txt) do ( 
echo %%i
psexec \\%%i ipconfig
)
 
Change it so that your batch file, instead of psexec, provides the system name from the file with a FOR loop.

That would be what I would do if I was going to do it.

Here is an example:


Code:
for /f %%i in (servers.txt) do ( 
echo %%i
psexec \\%%i ipconfig
)

Awesome! Exactly what I need!
 
Back
Top