Forum Discussion
The term 'Get-MessageTraceV2' is not recognized as a name of a cmdlet
I’ve recently encountered the same issue while using Get-MessageTraceV2 within an Azure PowerShell Function App with Managed Identity.
The strange part is, it’s totally intermittent. Sometimes the cmdlet works perfectly, and then on the next run, PowerShell suddenly says it’s not recognized, even though the module is installed and imported correctly.
What I’ve learned so far:
The issue seems to come from the ExchangeOnlineManagement module not consistently loading all cmdlets when the session is initialized via Connect-ExchangeOnline -ManagedIdentity.
I’m also using 'ExchangeOnlineManagement' = '3.*' in requirements.psd1.
The permissions and roles don’t seem to make a difference (Exchange.ManageAsApp, Exchange Admin, Tracking-View-Only, etc.).
What helped a bit on my end:
Connect-ExchangeOnline -ManagedIdentity -ShowBanner:$false
Import-Module ExchangeOnlineManagement -Force
Get-Command Get-MessageTraceV2 | Out-Null # Sanity check before running
If the cmdlet still isn’t found, restarting the Function App usually reloads it, but that’s obviously not ideal. I suspect there’s a module load timing or session context issue in how the Exchange module is initialized in Azure Functions; it's not tied to permissions.
You’re definitely not alone in this one; several of us have been seeing the same sporadic behavior lately.