windows - 用读取文本文件的for循环替换多行批处理文件

标签 windows batch-file cmd psexec

我目前有一个批处理文件,可以安排 chkdsk 在多台服务器上运行,等待下次重新启动 -

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"  

我试图了解如何构建一个 FOR 循环,该循环将从由 - 组成的 txt 文件中读取

server1  
server2  
server3  
server4  

txt 文件将位于我本地 e: 驱动器上的数据文件夹中。另外,有没有办法不必多次输入用户 ID 的密码?感谢指导!谢谢,祝大家新年快乐!

最佳答案

您可以使用 FOR,但您也可以创建一个名为 servers.txt 的文件,其中包含:

server1
server2
server3
server4

并运行这个命令:

c:\pstools\psexec @servers.txt ...your command...

PsExec 将在文件中列出的每台计算机上执行命令。请参阅psexec documentation here ,并查看 @file 参数。

关于windows - 用读取文本文件的for循环替换多行批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20806794/

相关文章:

python - 为什么 PATH 变量不影响 Windows 中的 subprocess.Popen

Windows cmd shell xcopy 到网络目录不起作用

powershell - 为什么从 Windows 批处理文件中运行 PowerShell 脚本时会输出不需要的空行?

windows - 计算日期 -10 天

windows - 在我的 Windows 7 系统上找不到 jdk?

c++ - 使用 Visual Studio 构建 Freetype 应用程序时出错

windows - 在 Windows 操作系统上编写 Gnuplot 脚本

windows - 如何从命令输出中查找和提取子字符串?

linux - 将循环的批处理文件转换为循环的 shell 脚本

node.js - 尝试构建 Cordova 应用程序时获取 'spawn cmd ENOENT' (event.js :85)