I currently have a batch file that schedules chkdsk to run on multiple servers pending the next reboot-
c:\pstools\psexec \\server1 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server2 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server3 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server4 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
c:\pstools\psexec \\server5 -d -u Domain\administrator cmd /c "echo Y | chkdsk c: /F"
I am trying to understand how to construct a FOR loop which will read from a txt file composed of -
server1
server2
server3
server4
The txt file will be located in the data folder on my local e: drive. Also, is there any way to not have to enter the password for the user ID more than once? Appreciate the guidance! Thx and a Happy New Year to all!
You could use a FOR, but you could also create a file named servers.txt
that contains:
server1
server2
server3
server4
and run this command:
c:\pstools\psexec @servers.txt ...your command...
PsExec will execute the command on each of the computers listed in the file. Please see the psexec documentation here, and see the @file
parameter.