PSExec 在启动作业中运行时永远不会完成

发布于 09-07 13:50 字数 1117 浏览 13 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一萌ing2024-09-14 13:50:41

对 psexec 命令尝试此操作,确保包含“-d”以不等待响应,并将计算机变量放在 psexec 之后:

d:\eps\pstools\psexec "\\$($computer)" /accepteula -u $userid -p $password -d cmd /c $command

Try this for the psexec command, ensuring you include "-d" to not wait for response, and put the computer variable right after psexec:

d:\eps\pstools\psexec "\\$($computer)" /accepteula -u $userid -p $password -d cmd /c $command
风吹短裙飘2024-09-14 13:50:41

此挂起问题发生在 Win2003 和 Win2008 服务器上。

大多数人通过回显和管道等解决方法来解决这个问题,以便 powershell 从 STDIN 获取一些输入。

但 powershell 中有一个解决方案。只需使用选项 -inputformat none 启动 powershell,例如:

powershell -inputformat none -command ...

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:

powershell -inputformat none -command ...
吖咩2024-09-14 13:50:41

请尝试 psexec 的 -accepteula 参数
就像

d:\eps\pstools\PsExec.exe -accepteula -u $userid  -p $password

来自

please try the -accepteula parameter to psexec
like

d:\eps\pstools\PsExec.exe -accepteula -u $userid  -p $password

from

眼泪都笑了2024-09-14 13:50:41
$computerList = Get-Content "D:\Data\serverlist.txt"      
$sb = 
{ 
    param($name)
        }
            $computer = $name
            $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 $computerLinst) {
    Start-Job $sb -ArgumentList $computer
}
$computerList = Get-Content "D:\Data\serverlist.txt"      
$sb = 
{ 
    param($name)
        }
            $computer = $name
            $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 $computerLinst) {
    Start-Job $sb -ArgumentList $computer
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文