1

Here's a script I'm trying to run, where $servers = @("computer1","computer2")

$servers | % {
    Start-Job -ScriptBlock {param($c) Get-EventLog -LogName "Application" -Newest 10 -ComputerName $c} -ArgumentList $_
}

The issue I'm having is that the jobs will stay "running". I thought perhaps this was an issue with passing parameters, so I removed that portion of the script, like so-

$servers | % {
    Start-Job -ScriptBlock {param($c) Get-EventLog -LogName "Application" -Newest 10} -ArgumentList $_
}

... and it worked. I then tried to specify the computername (to validate it was a parameter passing issue), like so -

$servers | % {
    Start-Job -ScriptBlock {param($c) Get-EventLog -LogName "Application" -Newest 10 -ComputerName "computer1"} -ArgumentList $_
}

The expected effect would be for it to get remote events on the same server twice. Instead I experienced the same issue as before: the script starts 2 jobs which both stay in a running state for... ever.

Any ideas or pointers?

Quick Edit:

I did also try to just use Get-EventLog on the remote machine without trying to run it in a job. That works fine.

Final Edit:

From Keith's response it looks like the issue is in my environment. I'll troubleshoot further on my own and accept Keith's answer as it pointed me to that conclusion.

6
  • How do you know they stay in a running state? Commented Jul 10, 2012 at 23:46
  • @splatteredbits I think just typing get-job and readig the 'state' coloumn. Commented Jul 11, 2012 at 7:30
  • Christian is right... I can tell the state of a job by... checking the state of jobs with the Get-Job cmdlet. Commented Jul 12, 2012 at 15:57
  • Why don't you pass directly to -argumentlist the $servers variable? Commented Jul 19, 2012 at 19:32
  • Wouldn't that end up with one Get-EventLog cmdlet running against two servers sequentially? If it even worked? I'll give it a try later. Commented Jul 19, 2012 at 19:36

2 Answers 2

1
+50

For what it's worth, I can't repro this error on either PowerShell V2 or V3:

8# 'build3','build5' | %{ Start-Job -ScriptBlock {param($c) Get-EventLog -LogName "Application" -Newest 10 -Comput
erName $c} -ArgumentList $_}

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
5               Job5            Running    True            localhost            param($c)...
7               Job7            Running    True            localhost            param($c)...


9# Get-Job

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Failed     False           localhost            param($c)...
3               Job3            Completed  False           localhost            param($c)...
5               Job5            Completed  True            localhost            param($c)...
7               Job7            Completed  True            localhost            param($c)...


10# Receive-Job -id 5

   Index Time          EntryType   Source                 InstanceID Message
   ----- ----          ---------   ------                 ---------- -------
 1397893 Jul 20 15:47  Warning     Group Policy Inte...   2248216579 The description for Event ID '-2046750717' in S...
 1397892 Jul 20 15:47  Warning     Group Policy Regi...   2248216579 The description for Event ID '-2046750717' in S...

It could be configuration issue. Do you have the Remote Registry service running on the servers? Also, you can run Receive-Job on the jobs even while they're running to get intermediate output & errors. Perhaps some error info would help track down the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for taking a look, Keith. Remote registry is running. If I take out the $c and replace it with either of the computer names in the list I'm trying to check, it works fine so I don't expect that it's a config issue on a remote machine. I've even tried running it from another source server in the environment.
1

What about using this ?

$servers = @("computer1","computer2")

$servers | ForEach-Object {$comp = $_
           Start-Job -ScriptBlock {Get-EventLog -LogName "Application" -Newest 10 -ComputerName $input} -InputObject $comp}

5 Comments

The solution I need is for local multitasking only. WinRM setup is out of scope for my present work. This very well may work for many cases though.
I am not sure I understand then what you are trying to do, why do you have $servers = @("computer1","computer2") if you are not trying to run it against multiple computers. Could you explain exactly what you would like the it to do and i can try help.
I'm running it against multiple computers, not on multiple computers. Invoke command will actually start the job on another machine. My solution will start mutiple Get-EventLog commands on the local machine which will run concurrently.
Ok I have changed the code try with this and let me know if it works
Same behavior. Stuck at "running"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.