title: Connect to Exchange Online with Powershell using Access Token
body: <p>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.</p>
  <p>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 &quot;Password length is more than 256&quot;.</p>
  <p><a href="https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2/" rel="nofollow noreferrer">https://o365reports.com/2020/07/04/modern-auth-and-unattended-scripts-in-exchange-online-powershell-v2/</a></p>
  <p><a href="https://www.michev.info/Blog/Post/1771/hacking-your-way-around-modern-authentication-and-the-powershell-modules-for-office-365" rel="nofollow noreferrer">https://www.michev.info/Blog/Post/1771/hacking-your-way-around-modern-authentication-and-the-powershell-modules-for-office-365</a></p>
  <p>We need to automate the process but not able to connect to exchange using access token.</p>
  <pre><code>$AccessToken = &lt;access-token-value&gt;
  $Authorization = &quot;Bearer {0} &quot; -f $AccessToken
  $Password = ConvertTo-SecureString -AsPlainText $Authorization -Force
  $UserCredential = New-Object System.Management.Automation.PSCredential(&quot;&lt;upn-value&gt;&quot;, $Password)
  Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
  </code></pre>
  <p>Error Message: I am getting error that password length is more than 256 characters.</p>