0

PowerShell 5.1

Invoke-Command -ScriptBlock {start-job {gsv}} -ComputerName Will
Invoke-Command -ScriptBlock {get-job} -ComputerName Will

Nothing was displayed. I couldn't retrieve any job.

1 Answer 1

2

Jobs are tied to the current session. The way you run Invoke-Command creates a new session with every invocation, so the second session naturally doesn't know anything about jobs of the first one.

Change your code to something like this, so both invocations run in the same session:

$session = New-PSSession -ComputerName Will
Invoke-Command -Session $session -ScriptBlock { Start-Job {gsv} }
Invoke-Command -Session $session -ScriptBlock { Get-Job }
Remove-PSSession $session
Sign up to request clarification or add additional context in comments.

1 Comment

Ok. I got it. Thank you for your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.