Calling Exchange Online PowerShell Cmdlets from C# With Modern Authentication

New Contributor

Hi Currently We can calling Exchange Online Commandlets With the below code :

 WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(""), exchangeSchema,
                   PowershellCommonUtilities.GetPSCredential(connectInfo.UserName, connectInfo.Password)); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
                connectionInfo.IdleTimeout = idleTimeout;
                connectionInfo.OpenTimeout = connectionTimeout;

                exchangerunspacepool = RunspaceFactory.CreateRunspacePool(minRunSpace, maxRunspace, connectionInfo);


We need to move this basic Authentication to Modern Authentication. Please let me know if anyone has achieved it.

3 Replies

Hi Vibhor,


Just wanted to check if you found any working solution for this. 

I.e trying to invoke exchange power shell commands from any service using oauth

Hello @Us9898  ,


We are using Exchange Online Remote PowerShell Module , to invoke cmdlets using modern authentication.


Hi @VibhorM ,


thanks for the quick reply, I am trying to execute this via backed-services.

which will not need user interaction. 


So i can get the token but after that i cannot connect to the API, via power shell. 

Wondering if you got it working .


thank you