Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to pass in the server parameter. The job is run in a seperate process and can't access your <code>$srv</code> string if you don't pass it as an argument. In PS3.0 you could use the "using" scope (ex. <code>$using:srv</code>), but in PS2.0 you need to use <code>param(..)</code>in your scriptblock and <code>-Argumentlist</code> to send the objects. Try this:</p> <pre><code>$server=@("SERVER1","SERVER2") foreach($srv in $server) { Start-Job -scriptblock { param($serv) $out=@() $XX=Get-EventLog -ComputerName $serv -LogName "application" | Where-Object {$_.InstanceID -ge 1000 -and $_.InstanceID -lt 1005} | select -First 5 foreach($x in $XX){ $obj=New-Object PSObject $obj|Add-Member -MemberType "NoteProperty" -Name Server -Value $srv $obj|Add-Member -MemberType "NoteProperty" -Name Index -Value $x.Index $obj|Add-Member -MemberType "NoteProperty" -Name EntryType -Value $x.EntryType $obj|Add-Member -MemberType "NoteProperty" -Name Source -Value $x.Source $obj|Add-Member -MemberType "NoteProperty" -Name InstanceID -Value $x.InstanceID $obj|Add-Member -MemberType "NoteProperty" -Name Message -Value $x.Message $out += $obj } $out } -ArgumentList $srv } $A = Get-Job | Wait-Job | Receive-Job $A | Out-GridView </code></pre> <p>If you want to exclude the runspaceid(one of the properties that start-job adds to specify where the object was created), try something like this :</p> <pre><code>$A | Select-Object -Property * -ExcludeProperty RunspaceID | Out-GridView </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload