How to correctly exit a remote job in a PowerShell session

I have several remote jobs starting with the Powerhsell invoke-command -session . In some cases, at least one of the deleted child jobs exits, but the local state of the PS session reports the jobs as "Running" and the session hangs waiting for the job to complete.

Is this a known bug in PSv2? Is there a workaround or method that allows the PS to correctly detect when the remote child job completes?

+6
source share
2 answers

When you use Invoke-Command -Session, I believe that you will need to use the Get-PSSession command to get the updated status. From Technet :

-Session

Runs the command in the specified Windows PowerShell sessions (PSSessions). Enter a variable containing PSSessions or a command that creates or receives a PSSession, such as a New-PSSession or Get-PSSession command.

0
source

How about: Remove-PSSession

 Get-PSSession | Remove-PSSession Remove-PSSession -Session (Get-PSSession) $s = Get-PSSession Remove-PSSession -Session $s 

OR

 $r = Get-PSSession -ComputerName Serv* $r | Remove-PSSession 

Powershell Kernel: Remove-PSSession

0
source

Source: https://habr.com/ru/post/989255/


All Articles