February 2019
Intermediate to advanced
626 pages
15h 51m
English
The AsJob parameter can be used with Invoke-Command, for example:
$session = New-PSSession PSTest
Invoke-Command -Session $session -AsJob -ScriptBlock { Start-Sleep -Seconds 120 'Done sleeping' }
The command finishes immediately, and returns the job that has been created.
While the job is running, the session availability is set to Busy:
PS> $session | Select-Object Name, ComputerName, AvailabilityName ComputerName Availability---- ------------ ------------Session1 PSTest Busy
Attempts to run another command against the same session will result in an error message.
Once the job has completed, the Receive-Job command may be used.
Read now
Unlock full access