"Receive-Job" Cmdlet in Windows PowerShell

Q

How to use "Receive-Job" cmdlet in Windows PowerShell?

✍: FYIcenter.com

A

You can use the "Receive-Job" cmdlet to receive output result from an existing background job by using the "-id n" or "-name xxx" to specify the background job.

The Receive-Job cmdlet gets the results that have been generated by the time that the Receive-Job command is submitted. If the results are not yet complete, you can run additional Receive-Job commands to get the remaining results.

By default, job results are deleted from the system when you receive them, but you can use the Keep parameter to save the results so that you can receive them again. To delete the job results, run the Receive-Job command again (without the Keep parameter), close the session, or use the Remove-Job cmdlet to delete the job from the session.

Here is an example of using the "Receive-Job" cmdlet to receive the output of an exisitng backgourndjob:

PS C:\fyicenter> start-job {get-process}
Id     Name            PSJobTypeName   State         HasMoreData     Command
--     ----            -------------   -----         -----------     -------
2      Job2            BackgroundJob   Running       True            get-process

PS C:\fyicenter> receive-job -id 2 -keep
Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
   2155       9     4964        724    92    19.78   4472 AdobeARM
    135       5     4264        220    57     1.56   4044 cmd
    161       8    26516       2232    74     1.65   3140 CmRcService
     51       3     1368       1052    46     4.29   1760 conhost
     52       3     1880       1128    46     3.39   4808 conhost
...

PS C:\fyicenter> receive-job -id 2 -keep
Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
   2155       9     4964        724    92    19.78   4472 AdobeARM
    135       5     4264        220    57     1.56   4044 cmd
    161       8    26516       2232    74     1.65   3140 CmRcService
     51       3     1368       1052    46     4.29   1760 conhost
     52       3     1880       1128    46     3.39   4808 conhost
...

Note that the "-keep" option keeps the out in the background job, instead of deleting it.

 

Managing Windows PowerShell Background Jobs

⇒⇒Windows PowerShell Tutorials

2016-10-08, 363👍, 0💬