Run about_Jobs for info
Jobs a run as children of the powershell session, so if the session goes, the jobs goes.
Get-command -noun job lists commands relating to running jobs
Can either run a scriptblock if quotes in curly brackets, like this…
1 2 3 4 5 6 |
PS C:\> Start-Job {Get-EventLog -List} -name eventJob Id Name PSJobTypeName State HasMoreData Location Command — —— ——————– ——– —————– ———— ———– 3 eventJob BackgroundJob Running True localhost Get-EventLog -List |
or a script file
1 2 3 4 5 |
PS C:\> Start-Job -FilePath ‘C:\dev\testscript.ps1’ -name filejob Id Name PSJobTypeName State HasMoreData Location Command — —— ——————– ——– —————– ———— ———– 5 filejob BackgroundJob Running True localhost ... |
Get-Job lists all jobs with Status.
HasMoreData means there is resulting data that can be retrieved
Don’t forget -Keep!
1 |
Receive-Job jobName -keep |
This keeps the data with the job whilst also retrieving it. Or you can assign the result to a variable:
1 |
$x = Receive-Job jobName |
Get-Job -IncludeChildJobs gives more details about sub-jobs, e.g. is a job ran on multiple computers.