I have a script that runs Invoke-VMScript from inside a function that starts a new Job with a ScriptBlock and then connects to vCenter with Connect-VIServer and executes Invoke-VMScript. The Invoke-VMScript and the entire function runs fine but I recently noticed that the PowerShell process created by he Start-Job stays running and never exits. When I use this script I start to see a lot of PowerShell processes running in the task manager and they never exit. I have tried various things like disconnecting the VISession after Invoke-VMScript and killing the Start-Job process, but nothing seems to work. Also, in the vSphere client if I look at the open session the sessions remain open.
Does anyone know what would cause this and how to kill that process?