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.
For what it’s worth, I can’t repro this error on either PowerShell V2 or V3:
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.