unable to connect to exchangeOnline with credential in powershell script

Mathieu FERLAY 21 Reputation points

Hi all,
I'm working on powershell scripts which should interact with exchange online.
I managed to do it in my laptop, with the following command:
Connect-ExchangeOnline -Credential $UserCredential -ShowBanner:$False -Verbose -EnableErrorReporting -LogDirectoryPath $logDirPath -LogLevel All
and got the following reporting info:

Successfully acquired token based on Credential flow;Successfully got a token from AAD;SessionPrefixName:ExchangeOnlineInternalSession

Now, when I deploy my scripts in the test vm which has the same configuration, they failed to connect:

3.0.0 ExchangeOnlineManagement MSOnline

I get the following report:

,CorrelationID: - Could not acquire token silently need UI authentication. No account or login hint was passed to the AcquireTokenSilent call

Do you know how it s possible and how to solve it?

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,240 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
516 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,403 questions
{count} votes

Accepted answer
  1. Glen Scales 4,431 Reputation points

    Because your trying to use a User to authentication it will use the Authorization code oAuth flow which requires user interaction (unless there is a cache refresh token which is only going to work for a limited amount of time). If you want to develop unattended scripts against Exo then look to use the certification authentication (which use the client credentials oauth flow) see https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps

    0 comments No comments

0 additional answers

Sort by: Most helpful