如何使用命令行界面在多台远程计算机上启动服务?

huangapple go评论43阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月16日 01:57:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75463719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定