小编Rob*_*ley的帖子

在start-job中运行时,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
}
Run Code Online (Sandbox Code Playgroud)

这创造了一堆工作....但是从来没有完成,如果我接收任何一个工作,我会回来

    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
Run Code Online (Sandbox Code Playgroud)

如果我运行如下函数,它执行得很好:

& …
Run Code Online (Sandbox Code Playgroud)

powershell psexec start-job

6
推荐指数
1
解决办法
5980
查看次数

标签 统计

powershell ×1

psexec ×1

start-job ×1