我有一个C#组件,它在PowerShell环境中执行Powershell脚本。突然它开始显示一些问题,现在,当我尝试执行以下操作时,它显示异常
Enter-PSSession -ComputerName 192.21.10.71 -Credential abc\admin
下面给出例外情况......
Enter-PSSession : Connecting to remote server failed with the following error message :
The WS-Management service cannot process the request. **This user is allowed a maximum
number of 5 concurrent shells, which has been exceeded.** Close existing shells or raise
the quota for this user. For more information, see the about_Remote_Troubleshooting
Help topic.
At line:1 char:16
+ Enter-PSSession <<<< -ComputerName 192.21.10.71 -Credential abc\admin
+ CategoryInfo : InvalidArgument: (192.21.10.71:String) [Enter-PSSession],
PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
我担心,这是因为我没有正确关闭/处理在c#组件中创建的运行空间。 这是从我的组件中提取的代码
......
Collection<PSObject> objPS = new Collection<PSObject>();
PowerShell powershell = PowerShell.Create();
PSCredential credential = new PSCredential(strUserName, password);
objRunspace = RunspaceFactory.CreateRunspace();
objRunspace.Open();
objPS = powershell.Invoke();
......
finally
{
objRunspace.Dispose();
}
我正在击败灌木丛,而不是找到这个问题的根本原因。
...谢谢