Forum Discussion

VibhorM's avatar
VibhorM
Copper Contributor
Apr 10, 2019

Calling Exchange Online PowerShell Cmdlets from C# With Modern Authentication

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

 WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://outlook.office365.com/PowerShell-LiveID"), 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.

9 Replies

  • Khaleck's avatar
    Khaleck
    Copper Contributor
    Hello,

    Basic Authentication is disabled since October 2022. So we're having the same issue. Did you find any solution or sample codes.


    Thanks,
  • Us9898's avatar
    Us9898
    Copper Contributor

    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

    • VibhorM's avatar
      VibhorM
      Copper Contributor

      Hello Us9898  ,

       

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

       

      https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps#connect-to-exchange-online-powershell-by-using-mfa

       

      • rajau06's avatar
        rajau06
        Copper Contributor

        VibhorM 

         

        Did you achieve this in c#. 

         

        Can you provide the sample code snippet

Resources