W2KSG: Asynchronous log access
Script Center Home > Microsoft Windows 2000 Scripting Guide > Scripting Solutions for System Administration > Logs > Managing Logs > Querying Event Logs Asynchronously Retrieving Event Log Statistics
Listing 12.11contains a script to asynchronously access the event logs. Rather than follow the WMI methods we can use the background jobs functionality in PowerShell version 2
Start-PSJob -Name job1 -Command "Get-EventLog -LogName application"
Get-PSJob
Receive-PSJob -Name job1 -Keep
Get-PSJob -Name job1 | Remove-PSJob
We create the job using Start-PSJob. Give it a name and the command we want to run. Get-PSJob can be used to view the status of jobs. Check the state for completed jobs.
Receive-PSJob pulls the data out of the job. Using the -keep parameter leaves the data available to be accessed again otherwise it is removed.
The job can be removed using Remove-PSJob as shown.


Read the complete post at http://richardsiddaway.spaces.live.com/Blog/cns!43CFA46A74CF3E96!1830.entry