質問

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で開始スクリプトが実行されます。Domain2のボックスで試しましたが、ドメインAdmin UserID(同じ結果)でログインしました。

役に立ちましたか?

解決

PSEXECコマンドでこれを試してみてください。「-D」を含めて、応答を待たないようにし、PSEXECの直後にコンピューター変数を配置します。

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

他のヒント

この吊り下げの問題は、Win2003およびWin2008サーバーで発生します。

ほとんどの人は、パワーシェルがstdinから何らかの入力を得るように、エコーやパイピングなどの回避策でこの問題を解決します。

しかし、PowerShell内には解決策が存在します。 Option -InputFormatなしでPowerShellを開始するだけです。

powershell -inputformat none -command ...

-accepteulaパラメーターを試してみてください

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

から

$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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top