#powershell TIP: Local vs Remote Background Jobs

It is common to use Start-Job to run a  background job against a remote machine via the -ScriptBlock parameter:

Start-Job -ScriptBlock { param($computer) Get-EventLog -LogName system -ComputerName $computer } -ArgumentList $computer

However, this always runs as a local BackgroundJob, consumes local resources and can be very slow.

Instead, consider using the -AsJob parameter of Invoke-Command to run the task as a RemoteJob on a remote host via -ComputerName i.e.

Invoke-Command -AsJob -ComputerName $computer -ScriptBlock { Get-EventLog -LogName system }

Leave a Reply