powershell - PSExec 在 start-job 中运行时永远不会完成

标签 powershell psexec start-job

我正在尝试在 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 box 上的 Powershell v2.0 中运行
我已经在域 2 中的一个盒子上尝试过,同时使用域管理员用户 ID 登录(结果相同)。

最佳答案

试试这个 psexec 命令,确保你包含“-d”以不等待响应,并将计算机变量放在 psexec 之后:

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

关于powershell - PSExec 在 start-job 中运行时永远不会完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3154449/

相关文章:

Powershell Job "Completed"但没有完成它的任务

Powershell 查询 - 找不到路径的一部分

azure - 使用 az powershell 创建 Azure AD 应用程序

command-prompt - 无法使用 PSExec 访问 - PSTools

teamcity - 远程机器上的 PSexec 从 Teamcity 运行时挂起

powershell - start-job 并行运行命令并在结果到达时输出结果

Powershell Start-Job 无法运行

c# - 是否可以以编程方式创建哈希规则?

powershell - 从 Confluence 页面获取限制

batch-file - psexec 退出并显示错误代码 1 - 双引号