Remote command call hangs synchronously

I am using a library System.Management.Automation

to invoke PowerShell commands using Remote Runspace. So I create a PowerShell object and call the script as such:

var remoteRunspace = RunspaceFactory.CreateRunspace(wsmanConnectionInfo);
remoteRunspace.Open();
var powershell = PowerShell.Create();
var powershell.Runspace = remoteRunspace;
string PsScript = "Some long running powershell script"
powershell.AddScript(PsScript);
powerShell.Invoke();

      

The selected call gets stuck and sometimes fails (e.g. 1 in 100 times where we saw this thread get stuck for over 24 hours). If we restart the remote computer, it will appear.

How do we fix this behavior? Is this a known issue in PowerShell? If so, will it work asynchronously PowerShell.BeginInvoke

? My guess is that it should improve some reliability since it will queue per thread ThreadPool

.

+3
c # powershell powershell-remoting


source to share


No one has answered this question yet

Check out similar questions:

733
Best way to parse command line arguments in C #?
8
Connect to Microsoft Exchange PowerShell inside C #
6
control.BeginInvoke () Vs Dispatcher Vs SynchronizationContext Vs .. - RELIABILITY
4
How can I determine which processes are started by the Start-Job command?
3
C # PowerShell with RunspacePool - How to import Exchange cmdlets like Get-Mailbox?
3
Get Java version from PowerShell remote server
2
stop looped powershell script and kill remote processes initiated by it
2
Capture Write-Host and Invoke-Command exit code on remote system
1
Fault tolerant remote processes and output
1
Is it possible to import-PSSession into an existing "OutOfProcessRunspace"



All Articles
Loading...
X
Show
Funny
Dev
Pics