我使用System.Management.Automation
库使用远程Runspace调用PowerShell命令。所以我创建了一个PowerShell对象并调用了一个脚本:
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();
突出显示的通话有时会卡住而不会出现(例如100次中的1次,我们看到此线程卡住超过24小时)。如果我们重新启动远程计算机,它就会出来。
我们如何解决此问题?它是PowerShell中的已知问题吗?如果是,将使用PowerShell.BeginInvoke
工作使其异步?我假设它应该提高一些可靠性,因为它会将它排在ThreadPool
线程上。