Home

Calling Exchange Online PowerShell Cmdlets from C# With Modern Authentication

%3CLINGO-SUB%20id%3D%22lingo-sub-424282%22%20slang%3D%22en-US%22%3ECalling%20Exchange%20Online%20PowerShell%20Cmdlets%20from%20C%23%20With%20Modern%20Authentication%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-424282%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Currently%20We%20can%20calling%20Exchange%20Online%20Commandlets%20With%20the%20below%20code%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3CSPAN%3EWSManConnectionInfo%20connectionInfo%20%3D%20new%20WSManConnectionInfo(new%20Uri(%22%3CA%20href%3D%22https%3A%2F%2Foutlook.office365.com%2FPowerShell-LiveID%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office365.com%2FPowerShell-LiveID%3C%2FA%3E%22)%2C%20exchangeSchema%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BPowershellCommonUtilities.GetPSCredential(connectInfo.UserName%2C%20connectInfo.Password))%3B%26nbsp%3BconnectionInfo.AuthenticationMechanism%20%3D%20AuthenticationMechanism.Basic%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20connectionInfo.IdleTimeout%20%3D%20idleTimeout%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20connectionInfo.OpenTimeout%20%3D%20connectionTimeout%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20exchangerunspacepool%20%3D%20RunspaceFactory.CreateRunspacePool(minRunSpace%2C%20maxRunspace%2C%20connectionInfo)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20need%20to%20move%20this%20basic%20Authentication%20to%20Modern%20Authentication.%20Please%20let%20me%20know%20if%20anyone%20has%20achieved%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-424282%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
VibhorM
Occasional Visitor

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.

Related Conversations
How to get the manager with the get-user?
Andy Kw in Office 365 on
4 Replies
ADFS and SSO for Exchange Online
Stephen Bell in Identity & Authentication on
17 Replies
ADFS Claims Based Rules - I'm stuck!
Stephen Bell in Identity & Authentication on
13 Replies
O365 MFA Mobile App Security Concern
Andy Baerst in Identity & Authentication on
6 Replies