PSExec never completes when run inside start-job
Asked Answered
H

4

6

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).

Hyetal answered 1/7, 2010 at 0:51 Comment(0)
P
4

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
Pragmatist answered 27/8, 2012 at 22:22 Comment(1)
Thank-you Lizz. The answer appears to be the placement of the computer value. I tried it with and without the -d and /accepteula (I've long since accepted eula :) ) and the enabling factor was making sure that the computername value was the first value after PSEXEC.Hyetal
F
2

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 ...
Fop answered 12/12, 2014 at 20:49 Comment(0)
S
0

please try the -accepteula parameter to psexec like

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

from

Syl answered 1/7, 2010 at 13:49 Comment(1)
Thank-you for the response. Adding -accepteula results in the same response + CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError PsExec v1.98 - Execute processes remotely Copyright (C) 2001-2010 Mark Russinovich Sysinternals - www.sysinternals.comHyetal
M
0
$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
}
Marquetry answered 18/12, 2013 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.