简体   繁体   中英

Connect to Exchange Online with Powershell using Access Token

I have acquired Access token and Refresh token from Azure AD. I need to connect to various O365 services from powershell using access token / refresh token. Can someone guide me how to proceed connecting to exchange server online.

Is there any other way we can connect to exchange server online using modern auth. I am using ExchangeOnlineManagement 2.0.3 version. I used below code-snippet based on the suggestion from the below listed blogs. I am getting error like "Password length is more than 256".

https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2/

https://www.michev.info/Blog/Post/1771/hacking-your-way-around-modern-authentication-and-the-powershell-modules-for-office-365

We need to automate the process but not able to connect to exchange using access token.

$AccessToken = <access-token-value>
$Authorization = "Bearer {0} " -f $AccessToken
$Password = ConvertTo-SecureString -AsPlainText $Authorization -Force
$UserCredential = New-Object System.Management.Automation.PSCredential("<upn-value>", $Password)
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true

Error Message: I am getting error that password length is more than 256 characters.

Sorry for the delay.

I understand your requirement. I know using New-PSSession with Basic Authentication is going to be deprecated soon, so you are looking for an alternative.

But it's not supported to use an access token to connect to Exchange Online currently due to AADSTS50052: The password entered exceeds the maximum length of '256'. . I don't think you need worry about it. By then Microsoft should be able to provide coverage for all the functions that V1 modules have.

See a similar question here .

I found the solution. Refer to the article below, We need to install ExchangeOnlineManagement 2.0.3 version and connect using certificate. Follow the steps mentioned in the below post.

https://www.quadrotech-it.com/blog/certificate-based-authentication-for-exchange-online-remote-powershell/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM