How it works...
The Start-Job cmdlet starts a normal background job. The remote connection is handled within the job script block. The script block runs as a separate PowerShell process. The remote connection is managed by Get-Process, so it is destroyed when the data is returned. Note that the location says localhost, which means that the job is running locally.
In the second job, you're using Invoke-Command to run the command and control the connection to the remote machine. Invoke-Command uses standard PowerShell remoting for connectivity to remote machines. The –AsJob parameter brings the PowerShell job engine into play. Note that, this time, the PSJobTypeName is RemoteJob and that the location is hdf01 (the remote machine).
The big difference ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access