PSExec 在启动作业中运行时永远不会完成
我正在尝试在 48 台计算机的列表上执行 cmd 文件。我不想按顺序执行并等待完成,因为每个 cmd 大约需要 10 分钟才能完成。 WinRM 不是一个选择。 WMI 也不是。 PSExec 是一个选项......但我似乎无法让它在 Start-Job 中工作。
我正在做类似的事情:
$sb = {
param
(
$computer = "serverw01",
$userid = "domain2\serviceid",
$password = 'servicepw',
$command = "cd /d d:\ && updateAll.cmd"
)
d:\eps\pstools\PsExec.exe -u $userid -p $password "\\$($computer)" cmd /c $command
}
foreach ($computer in Get-Content "D:\Data\serverlist.txt") {
Start-Job $sb -ArgumentList $computer
}
这会创建一堆作业......但是永远不会完成,如果我在其中任何一个上接收作业,我会回来,
PS> get-job | receive-job -Keep
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
如果我运行如下函数,它执行得很好:
& $sb -computer "serverw01"
启动脚本运行在Server 2008r2 盒子上的 Powershell v2.0 我在使用域管理员用户 ID 登录时在域 2 中的盒子上尝试过(相同的结果)。
I'm trying to execute a cmd file on a list of 48 computers. I don't want to execute and wait for completion sequentially because each cmd takes about 10 minutes to complete. WinRM isn't an option. Neither is WMI. PSExec is an option....but I can't seem to make it work inside of Start-Job.
I'm doing something like:
$sb = {
param
(
$computer = "serverw01",
$userid = "domain2\serviceid",
$password = 'servicepw',
$command = "cd /d d:\ && updateAll.cmd"
)
d:\eps\pstools\PsExec.exe -u $userid -p $password "\\$($computer)" cmd /c $command
}
foreach ($computer in Get-Content "D:\Data\serverlist.txt") {
Start-Job $sb -ArgumentList $computer
}
This creates a bunch of jobs....but the never complete and if I Receive-Job on any of them i get back
PS> get-job | receive-job -Keep
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
it executes just fine if I run the function like:
& $sb -computer "serverw01"
Initiating script is run in Powershell v2.0 on Server 2008r2 box
I've tried it on a box in domain2 while logged in with a domain admin userid (same result).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对 psexec 命令尝试此操作,确保包含“-d”以不等待响应,并将计算机变量放在 psexec 之后:
Try this for the psexec command, ensuring you include "-d" to not wait for response, and put the computer variable right after psexec:
此挂起问题发生在 Win2003 和 Win2008 服务器上。
大多数人通过回显和管道等解决方法来解决这个问题,以便 powershell 从 STDIN 获取一些输入。
但 powershell 中有一个解决方案。只需使用选项 -inputformat none 启动 powershell,例如:
This hanging issue occurs on Win2003 and Win2008 servers.
Most people solve this issue with a workaround like echoing and piping so that powershell gets some input from STDIN.
But there exists a solution within powershell. Just start powershell with the option -inputformat none like:
请尝试 psexec 的 -accepteula 参数
就像
来自
please try the -accepteula parameter to psexec
like
from