How to maintain powershell session for Exchange Online for multiple tenant users?

We are executing powershell scripts for exchange online using c#.
We created WCF services for executing different commands and calling that services.
While doing login we are accepting credentials of user's office 365 account. And stores the user information in WSConnectionInfo class

WSManConnectionInfo connectionInformation = "some user connection information" connectionInformation  = new WSManConnectionInfo (new Uri("https://outlook.office365.com/powershell-liveid/"),

"http://schemas.microsoft.com/powershell/Microsoft.Exchange", new PSCredential(logedInUserName, GetPassword(logedInUserPassword)));                using(Runspace runspace=RunspaceFactory.CreateRunspace(connectionInformation))    {                    using (PowerShell powershell = PowerShell.Create()) { //  code for executing powershell command } }



So all the information about connection is stored in ConnectionInformation object.
Whenever I executes the commands, I send ConnectionInformation object to runspace.
Relevant data of user's account get displayed mailboxes, distribution groups etc. 
Now the problem is that, whenever we does the login for single user, it is working fine. But if we do login for 
multiple users at a time, it stores the credentials for latest logged in user and all operations gets executed for the 
account of that user.
We want to maintain the different sessions for different users.
How to do this? 

--

Thanks in Advance

  
September 11th, 2015 10:20am

If they are different tenants then you need to open a separate Session for each Tennant (which involves maintaining a separate Runspace for that tenant). Just specifying the connectioninformation isn't enough because that won't alter the underlying WSMan session which will be specific to that tenant (eg Autodiscover will resolve the correct server etc.).

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 11:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics