title: Powershell : Create runspace failed
body: <p>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</p>
  
  <pre><code>Enter-PSSession -ComputerName 192.21.10.71 -Credential abc\admin
  </code></pre>
  
  <p>The exception is given below...</p>
  
  <pre><code>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 &lt;&lt;&lt;&lt;  -ComputerName 192.21.10.71 -Credential abc\admin
      + CategoryInfo          : InvalidArgument: (192.21.10.71:String) [Enter-PSSession], 
  PSRemotingTransportException
      + FullyQualifiedErrorId : CreateRemoteRunspaceFailed
  </code></pre>
  
  <p>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</p>
  
  <pre><code>    ......
  Collection&lt;PSObject&gt; objPS = new Collection&lt;PSObject&gt;();
  PowerShell powershell = PowerShell.Create();
  PSCredential credential = new PSCredential(strUserName, password);
  objRunspace = RunspaceFactory.CreateRunspace();
  objRunspace.Open();
  objPS = powershell.Invoke();
  ......
  finally 
          {
              objRunspace.Dispose();
          }
  </code></pre>
  
  <p>I am beating the bush, instead of finding the root cause of this issue.</p>
  
  <p>Thanks...</p>