英文:
How can I use CLI to start a service on multiple remote PCs?
问题
由于我的环境限制,我无法使用Powershell来启动这个服务,需要使用命令行界面(CLI)。我需要能够在大约100台工作站上启动单个服务。
我已经能够远程在单台PC上启动服务,但我希望它能指向一个计算机列表的文本文件。
这是在单台工作站上运行的命令
sc \\remotepc start [service]
我尝试过这个命令,但它无法启动远程工作站上的服务。
for /f %H in (D:\Server\workstationlist.txt) do net start [service]
英文:
Due to the constraints of my environment, I am unable to use Powershell to start this service and need to use CLI. I need to be able to start a single service on apporx. 100 workstations.
I have been able to start the service remotely on a single PC, but I would like for it to point to a txt list of computers.
This is the command that will work on a single workstation
sc \\remotepc start [service]
I have tried this command but does not start the service on the remote workstation
for /f %H in (D:\Server\workstationlist.txt) do net start [service]
答案1
得分: 0
我找到了几种执行这些命令的方法
for /f %i in (computerlist.txt) do sc \\%i start winrm
computerlist.txt 是一个文本文件,包含远程计算机的名称,每行一个名称。您还可以用逗号分隔的计算机名称列表替换它。
For /f "tokens=1" %i in ("Computer1,Computer2,Computer3") do sc \\%i start winrm
其中'Tokens=1'告诉for循环根据逗号字符将列表分割为单独的标记,并仅使用第一个标记作为计算机名称。
英文:
I was able to find a few ways to execute these commands
for /f %i in (computerlist.txt) do sc \\%i start winrm
computerlist.txt is a text file containing the names of the remote computers with one name per line. You can also replace this with a comma-separated list of computer names.
For /f "tokens=1" %i in ("Computer1,Computer2,Computer3") do sc \\%i start winrm
Where 'Tokens=1' tells the for loop to split the list into separate tokens based on the comma character and use only the first token as the computer name
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论