question

DevTeam-7257 avatar image
2 Votes"
DevTeam-7257 asked DevelopX-9563 answered

New-ExoPSSession : AADSTS50052: The password entered exceeds the maximum length of '256'. Please reach out to your admin to reset the password

There is way given by the Microsoft for connecting to Exchange Online PowerShell using the Client ID and client secret using Preview version described in https://docs.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

enter image description here
13504-stackoverflow01.png

But this one is giving a problem with Password length.

Here is the PowerShell script I am using: $AuthenticationResult = Invoke-RestMethod -Uri https://login.microsoftonline.com/{tenant_Name}/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://outlook.office.com/"; "client_id" = "ClientID"; "client_secret" =" CLientSecret "}

$PlainPassword = “bearer ” +$AuthenticationResult.access_token

$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force

$UserName="userName"

$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword

Connect-ExchangeOnline -Credential $Credentials

enter image description here
13505-stackoverflow02.png

Can anyone help me with this?

Thanks in Advance.


office-exchange-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

KyleXu-MSFT avatar image
0 Votes"
KyleXu-MSFT answered

I noticed that there are some different between your operation and the suggestion way:
1. You didn't use the suggested way to get token.
2. In the step 2, you just need to use UPN and token. In your operation you combine the access token and "bearer" as the new value. I think it is the reason why the length is exceed the limitation.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GaneshM-1706 avatar image
0 Votes"
GaneshM-1706 answered

I am also facing same issue. I acquired access token from NodeJS application. I pass the token to powershell to execute few exchange cmdlets. When i try to connect using Connect-ExchangeOnline, i am getting error password length is more than 256 characters.

 $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 
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WilliamCook-9720 avatar image
0 Votes"
WilliamCook-9720 answered WilliamCook-9720 edited

Bumping this. Same issue - both using just the token and as "Bearer tokenString". Acquiring the token using a Go app via the rest methods.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DevelopX-9563 avatar image
0 Votes"
DevelopX-9563 answered

I have same issue, as part of Connect-ExchangeOnline (New-ExoPSSession used internally), any news?
It definitely should be fixed to be able to use MFA with auto-renewed access token inside service account when access via remote PowerShell.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.