Friday, December 27, 2013

Use PSEXEC to run a command against a list of machines and have it run a command from the machine

Start by creating a list of computers that need the command run on them (pclist.txt.).  Use the file copy command for /f %a in (pclist.txt) do copy /y \\server\share\file.bat \\%a\c$\ to copy the files to the machines in the pclist.txt.  In this example the file is copied to the root.  Next, from an elevated command prompt run:
psexec @pclist.txt c:\file.bat

This will execute the batch or exe file you copied to the remote machine on the remote machine. 
If you need to authenticate run:
psexec @pclist.txt -u domain\user c:\file.bat and it will prompt for a password.



No comments:

Post a Comment