Link to home
Start Free TrialLog in
Avatar of TECH_GUY_MC
TECH_GUY_MC

asked on

Running PSEXEC under parallel processing Fail

I am running the following PSEXEC code and this works fine if I run it serially in a normal powershell script loop.
c:\scripts\message\psexec.exe -s -i -d \\$_ wscript.exe "\\server\share\myscript.vbs" /message:"****A Message****"

When I try running it as a parallel processed task, I get the following message

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ...Couldn't access :
Connecting to ...
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ...Couldn't access :
Connecting to ...


Below is my Code for the Parallel processed task.
# Loop through the server list
 
Get-Content "computers.txt" | %{
 
  # Define what each job does
 
  $ScriptBlock = {
c:\scripts\message\psexec.exe -s -i -d \\$_ wscript.exe "\\server\share\myscript.vbs" /message:"****A Message****"
    Start-Sleep 15
  }
 
  # Execute the jobs in parallel
 
  Start-Job $ScriptBlock
}
 
Get-Job
 
# Wait for it all to complete
 
While (Get-Job -State "Running")
{
  Start-Sleep 10
}
 
# Getting the information back from the jobs
 
Get-Job | Receive-Job
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just to add to above: The Wait loop is not necessary, you can do the same with
   get-job  | wait-job