1
votes

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.

2
How do you know they stay in a running state?Aaron Jensen
@splatteredbits I think just typing get-job and readig the 'state' coloumn.CB.
Christian is right... I can tell the state of a job by... checking the state of jobs with the Get-Job cmdlet.Chris N
Why don't you pass directly to -argumentlist the $servers variable?CB.
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.Chris N

2 Answers

1
votes

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.

1
votes

What about using this ?

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

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