4

I'm experimenting with jobs in PowerShell, but I'm unable to receive results. Here's some output from the shell.

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> dir


    Directory: C:\Users\Administrator


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d-r--         6/18/2013  11:52 AM            Contacts
d-r--         6/20/2013   1:00 PM            Desktop
d-r--         6/18/2013  11:52 AM            Documents
d-r--         6/18/2013  11:52 AM            Downloads
d-r--         6/18/2013  11:52 AM            Favorites
d-r--         6/18/2013  11:52 AM            Links
d-r--         6/18/2013  11:52 AM            Music
d-r--         6/18/2013  11:52 AM            Pictures
d-r--         6/18/2013  11:52 AM            Saved Games
d-r--         6/18/2013  11:52 AM            Searches
d-r--         6/18/2013  11:52 AM            Videos
-a---         6/20/2013  12:57 PM      13404 services.html


PS C:\Users\Administrator> Start-Job -ScriptBlock { dir }

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Running    True            localhost             dir


PS C:\Users\Administrator> get-job

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Completed  False           localhost             dir


PS C:\Users\Administrator> Receive-Job -id 1
PS C:\Users\Administrator>

The output above is from a stock Win2008 R2 server that I built and upgraded to a domain controller. It's the only computer in the domain and not associated with any other computers.

I don't have problems receiving results when I run these commands on other computers. What would cause this job to not produce output? Where should I look to debug this problem? I looked through the event logs and didn't find any problems.

Edit: Thanks everyone for your help, but I'm going to consider this question resolved. I believe something was corrupted during the build of the server or installation of a patch since no other computer exhibited the behavior. I've since migrated the data and rebuilt the server and it's working fine.

Starfish
  • 1,083
  • 10
  • 23

2 Answers2

1

Maybe the directory you're searching happens to be empty on this computer, but not the others. You might try supplying a -path parameter to dir/gci within the job:

Start-Job -ScriptBlock { dir -path c:\folderThatIsForSureNotEmpty }
Community
  • 1
  • 1
noam
  • 1,914
  • 2
  • 20
  • 26
1

Start-Job does not start jobs in the current directory. It starts a new PowerShell process, and uses a different directory for that job. As another answer suggests, its possible this directory is empty on your server, so nothing is returned. What happens if you just write some output in your Start-Job script block? Do you get any output?

Start-Job { Write-Host "In ur job." ; Get-Location ; dir } | Wait-Job | Receive-Jo
Aaron Jensen
  • 25,861
  • 15
  • 82
  • 91
  • Please read my post again. You will see at the bottom that I am already running `Receive-Job` and receive no output. – Starfish Jul 10 '13 at 14:39
  • Oops. I was wondering why the answer seemed so obvious. I've updated my answer with further suggestions for debugging. – Aaron Jensen Jul 10 '13 at 14:47