Hi ,
I have a C# component which executes Powershell scripts in powershell environment. Suddenly it started to show some issues, Now, when I try to execute the following, it shows exception
Enter-PSSession -ComputerName [IP] -Credential abc\admin
The exception is given below...
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 [IP] -Credential abc\admin
+ CategoryInfo : InvalidArgument: ([IP]:String) [Enter-PSSession],
PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
I fear, this is because I haven't properly closed / disposed the runspaces created in c# component.
Here is the code extracted from my component
......
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();
}
I am beating the bush, instead of finding the root cause of this issue.
Thanks...