1

Jason Archer helped me solve my last issue, but in testing his solution I stumbled across the real problem. My server won't run chained background jobs correctly, but my laptops will.

If I run the scripts in the previous problem on my laptops, they work perfectly. Script A starts Script B as a background job, and Script B calls Script C from within that job, and all output is received. If I run the exact same scripts on my server, Script A calls Script B, and Script B hangs indefinitely. If I run Script B directly, it executes perfectly on the server or the laptops. It's something about the job being backgrounded that's killing me.

$PSVersionTable returns the same results on all computers, though obvious I had to use different installers on WinXP vs Win2003R2.

What might be causing the difference in behaviour?

Is there any way to troubleshoot what's going on in the background jobs? If I could see the command lines being received (I've logged what's being sent, but sometimes things drift), or what object is really hanging things, maybe it would help, but the debugger won't take me there. Perhaps there's a way to call the job within the ISE as if it were running in the background?

Community
  • 1
  • 1
codepoke
  • 1,272
  • 1
  • 22
  • 40

2 Answers2

1

Ah. I think maybe I have my answer.

Laptop:

PS Z:\jobs> winrm quickconfig
WinRM already is set up to receive requests on this machine.
WinRM already is set up for remote management on this machine.

Server:

PS D:\jobs> winrm quickconfig
WinRM already is set up to receive requests on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.

If anyone can confirm this or give info on troubleshooting background jobs, I'll mark the question answered.

codepoke
  • 1,272
  • 1
  • 22
  • 40
  • I doubt the solution to my issue will be to enable remoting on all my servers, but I can go with Start-Process to start these as foreground jobs. That's working. – codepoke Mar 04 '11 at 16:51
0

You can get the output result of a Powershell job by using Receive Job. For instance, if we had a job like as follows:

$myJob = start-job -ScriptBlock  { 
    Write-Output "Some stuff happening..."
    throw "Hello World!"
}

We could get the output of the job like this:

Receive-Job $myJob    #prints the message and exception
Adam Prax
  • 6,413
  • 3
  • 30
  • 31
  • Per my original question, I am having no trouble receiving my jobs when run on a computer with remoting enabled. This is not the point of confusion. I'm trying (though not very hard right now) to find out whether the problem is with WMI or remoting. I've heard answer to indicate either, but I'm close to having remoting enabled on all our servers. That will be happy day. – codepoke May 05 '11 at 12:08