Hey folks! I'm new to PowerShell and I've been trying to help someone with a problem they're facing. They use the ExchangeOnlineManagement Module to manage multiple tenants, and it connects fine without admin rights using Connect-ExchangeOnline. However, when they run PowerShell as an admin, they encounter this error:
* "A specified logon session does not exist. It may already have been terminated."
* Error Code: 0xffffff80070520
* Exception Type: MsalServiceException — OperationStopped
* Source: ExchangeOnlineManagement.psm1:591
We checked their installed modules and there's a lot that I don't have, including multiple Az modules. They don't mind if we uninstall everything to troubleshoot. Here's what we already tried:
* Running PowerShell with the -noprofile option
* Installing the latest PowerShell 7 version
* Checking for custom profiles (none found)
* Reinstalling the ExchangeOnlineManagement module
Next steps I'm considering include:
* Removing all Az modules and any unnecessary ones
* Running sfc /scannow and DISM
* Testing with an older version of the module
* Clearing out the TokenBroker cache
* Trying a different Windows profile on the same PC
I'm thinking the issue may be related to an expired login token, especially since it only happens with admin access. I'd appreciate any advice on this!
4 Answers
The key thing here is to run PowerShell without admin rights. When you run it as admin, it changes the user context, preventing the necessary web browser from launching to log in. If you’re not making system-level changes, there’s really no need to elevate privileges. That explains why it worked for others—you might have been using accounts with local admin rights!
Exactly! I had the same issue, and once I stopped running as admin, everything worked. Just a restriction issue.
I've faced similar issues before. Running a Disconnect-ExchangeOnline might help to clear any stale tokens, even if the current connection is failing. Also, instead of grabbing the latest version of any module, it’s smart to check which ones are most frequently downloaded recently—those tend to be the more stable options. And remember, modules can be installed in different directories, so make sure you’re using the same folder to avoid any weird behaviour.
I created an app registration with the required permissions to connect properly. That might be another solution if the token issue persists.
You might want to look for similar issues since there was a post about this just a few days ago. Also, remember not to run it with elevated privileges and check for any updates related to WAM authentication.

Thanks for clarifying that! It makes sense now why it worked for the other accounts but not for theirs.