0

特定のイベントについて、コンピュータ イベント ログのリストを検索しています。このリストは 7,000 以上のシステムです。これにランスペースを利用してもらいたいです。次のコードがありますが、機能しません。戻り値が null のように見え、もちろん CSV エクスポートが失敗します。

助言がありますか?

ありがとう!

# Max Runspaces
$Throttle = 5 #threads

# What is the total number of events to pull?
$eventMax = 10

# Which event log do we want to pull from?
$eventLog = "System"

$eventEntryID = "7023"

$eventMessage = "The Windows Modules Installer service terminated with the following error: 
The configuration registry database is corrupt."

# What is our source file, the one with ll the file names.
$computers = Get-Content "c:\temp\Louis\hostsins.txt"

# What is our CSV file
$outFile = "c:\temp\Louis\SearchEventLogResultsINS.csv"

$ScriptBlock = {
    Param (
        [string]$sComputer
    )

    $RunResult = Get-WinEvent -Oldest  -ComputerName $sComputer -FilterHashtable @{LogName = $eventLog; ID = $eventEntryID;} | 
                 where{$_.Message -eq $eventMessage} | 
                 Select machinename, TimeCreated, ID, LevelDisplayname, Message 
    write-host $RunResult

    Return $RunResult
}

$RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $Throttle)
$RunspacePool.Open()
$Jobs = @()

$computers | % {

   write-host $_

   $Job = [powershell]::Create().AddScript($ScriptBlock).AddArgument($_)
   $Job.RunspacePool = $RunspacePool
   $Jobs += New-Object PSObject -Property @{
        RunNum = $_
        Pipe = $Job
        Result = $Job.BeginInvoke()
   }
}

Write-Host "Running.." -NoNewline
Do {
    Write-Host "." -NoNewline
    Start-Sleep -Seconds 1
} While ( $Jobs.Result.IsCompleted -contains $false)
Write-Host "All jobs completed!"

$Results = @()
ForEach ($Job in $Jobs){
    $Results += $Job.Pipe.EndInvoke($Job.Result)
}

$Results | Export-Csv $outFile
4

1 に答える 1