You cannot create multiple System.Management.Automation runspaces in a web application for two or more different users if you use implicit credentials


Update: This information has been published as a KB article: https://support.microsoft.com/en-gb/kb/3115600.

When you try and allow multiple users to create System.Management.Automation runspaces in a web application, if you are using implicit credentials (i.e., credentials from impersonation), you will notice that only the first user that accesses the web application is able to call CreateRunspace.  All subsequent requests will fail with an exception similar to:

System.Management.Automation.PSInvalidOperationException
at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize
at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager..ctor
at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor
at System.Management.Automation.Remoting.ClientRemoteSessionImpl..ctor
at System.Management.Automation.Internal.ClientRunspacePoolDataStructureHandler..ctor
at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.CreateDSHandler
at System.Management.Automation.Runspaces.RunspacePool..ctor
at System.Management.Automation.RemoteRunspace..ctor
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace
at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace

I’ve tried in vain to find a workaround with no luck so in the end I’ve reached out to the Windows devs for help. The Windows devs have confirmed that this is in fact *by design* and in order to be able to create multiple System.Management.Automation runspaces in a web application for two or more different users you need to pass in explicit credentials.

In other words, if you need this to work, make sure that ASP.Net impersonation is not enabled on the IIS virtual directory, remove any Windows impersonation logic from your code and prompt your users for a username and password.

Comments (0)

Skip to main content