Open dijitali opened 7 years ago
I'll try to reproduce this scenario but it may be a little while before I'm able to. It has been sometime since I raised this issue and I don't have the same environment available to me.
Should be able to find some time to re-test in the next couple of weeks.
When running a PowerShell Job which creates a PSDrive to a remote server using credentials, the job can "hang" in the
Running
state even when all actions have been completed. This is apparently caused by the way the PSCredential object is passed to the job, as illustrated in the script example below.If the PSCredential object is created within the job, it will hang. However, if the PSCredential object (created in exactly the same way) is passed as a parameter, the job will finish normally.
Steps to reproduce
C:\scripts\MySimpleJob.ps1
Launch the above script as a job without passing the $DeploymentCredential parameter and observer it takes roughly 180 seconds to complete:
Whereas if credentials are passed as a parameter, the job completes in a couple of seconds:
Expected behavior
Jobs execute and change to
Completed
status within a few seconds.Actual behavior
In PowerShell 4.0 the jobs appear to stay in the
Running
state indefinitely. In PowerShell 5.1 and 6.0.0-alpha the jobs stay in theRunning
state for ~180 seconds and then change toCompleted
.Environment data
I have tested this on OS versions Server 2008 R2 (PowerShell 4.0 and 5.1) and Server 2012 R2 (PowerShell 5.1 and 6.0.0-alpha). Behaviour appears to be the same regardless of OS (on both executing server and remote server that is used as a PSDrive).