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

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Rob Wiley
  • 85
  • 1
  • 7

4 Answers4

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
SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59
Lizz
  • 1,442
  • 5
  • 25
  • 51
  • 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. – Rob Wiley Aug 27 '12 at 23:09
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 ...
itsme86
  • 19,266
  • 4
  • 41
  • 57
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
}
TICK
  • 1
  • 1
0

please try the -accepteula parameter to psexec like

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

from

nineowls
  • 611
  • 4
  • 5
  • 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.com – Rob Wiley Jul 01 '10 at 16:08