CTP3 –PowerShell Jobs pt 2
We use start-job to create a new job. I have found it best to supply a name so that the jobs can be tracked. The other parameter is the PowerShell commands that will be run in the job. If you want to run a script use the –FilePath parameter to define its location
PS> Start-Job -Name j1 -ScriptBlock {get-process}
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
1 j1 Running True localhost get-process
PS> Get-Job
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
1 j1 Running True localhost get-process
Get-Job is used to view the progress. When the job has finished the status changes to completed.
PS> Get-Job
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
1 j1 Completed True localhost get-process
We can retrieve the data using
Receive-Job -Name j1 -Keep
The –Keep parameter leaves the data in place. If it is not specified the data is wiped from the job after display.
The job can be deleted from the queue by using
Remove-Job -Name j1


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