Jun 10, 2015 03:56 AM|hemaanshu|LINK
Well, I seem to have found the problem...
With the first call to powershell (wsman), WSMan API Initialize (WSManInitialize function) is called which returns a handle unique to the user. Later, WSMan Session Initilize (WSManCreateSession function) is called which takes the handle and establishes
the powershell session.
If this goes well, the user gets the remote session and can execute remote commands...
Later, when the user wants to close the session, user can call runspcace.Close or runspace.Dispose methods. This should ideally do cleanup and close session and deinitialize WSMAN API.
But, I observed that, calling runspace.Dispose or runspace.Close only closes the session but does not deinitialize the WSMan API.
Hence, when the second user logs in, the create session API fails as the handle corresponds to previous (different) user...
If I re-cycle the IIS Application pool and, then login the calls are successful.
Now I am searching for means to ensure that the WSMan API is deinitialized properly when a user logs off (terminates their remote powershell session)
Here, either I am doing something very silly or it is a bug with Powershell SDK or IIS.