对列表中的每个计算机名运行PSEXEC

时间:2017-12-13 21:24:40

标签: batch-file remoting psexec

我需要能够为txt文件列表中的每台计算机运行以下命令。 txt文件将包含计算机名称,每行1个,并且id需要将每行导入CompName变量。以下是我目前的情况。非常感谢帮助。

:Start
@echo off

Set /p CompName=Computer Name:
Set /p BatName=Batch File Name:

md \\%CompName%.company.local\C$\ScriptFiles\
Copy  "\\Server-Name\Installs\Scripts\%BatName%.bat" "\\%CompName%.company.local\C$\ScriptFiles\Run.bat" 


psexec \\%compname% -i -h -s  "C:\ScriptFiles\Run.bat"

GOTO Start

1 个答案:

答案 0 :(得分:0)

for /f "skip=3 delims=\" %%A in ('net view ^| findstr /v /C:"The command completed successfully"') do Echo %%A

会给你一个计算机名单。把它放在一个文件中。

for /f "skip=3 delims=\" %%A in ('net view ^| findstr /v /C:"The command completed successfully"') do Echo %%A >> Computername.txt

然后输入打开电脑

 wmic /node:@"Computername.txt" process call create "\\\\Server-Name\\Installs\\Scripts\\%BatName%.bat"