Assembly loading error after trying to connect to Exchange Online in script when calling from app

Resolved

Assembly loading error after trying to connect to Exchange Online in script when calling from app

avatar

UPDATE: Solved - see my follow up

Struggling with this one!

I have a script that pulls mailbox details from Exchange Online using a certificate and app-registration in Azure (so it's non-interactive, but don't think this is relevant).

The script runs by itself (directly) without issue. However, if I try and call it from an app I get an error.

Command:
$session:UserMailbox = Invoke-PSUScript -Name 'Exchange\Get-ExoMailbox.ps1' -Parameter @{ Email = ($session:User).mail } -Wait -TrustCertificate -Environment 'PowerShell 7 - Exchange'

Error:
Could not load file or assembly 'Microsoft.Exchange.Management.ExoPowershellGalleryModule, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Assembly with same name is already loaded

I've specified different environments for both app and script, so should be in their own runspaces. But the error seems to indicate otherwise...

The 'PowerShell 7 - Exchange' environment is set to load the ExchangeOnlineManagement module. I've also tried loading it directly in the script. Either way, same problem.

Version: 2026.2.4

All Comments (1)

avatar

Update:

Ok, figured this out. It was an established session to Exchange server onprem that was causing the EOM module to get flustered.

Panic over, ty if you've already read the above!