Forum Discussion
Get-MessageTraceV2 not recognized
I'm updating a script that automatically pulls message traces in Exchange Online. From my understanding, the Get-MessageTrace cmdlet will no longer work at the end of the month, and it needs to be upgraded to Get-MessageTraceV2. Below is the script.
# Connect to Exchange
Online Connect-ExchangeOnline -ShowBanner:$False
# Define the start and end dates for the mail trace
$startDate = (Get-Date).AddDays(-7).ToString("MM/dd/yyyy")
$endDate = (Get-Date).ToString("MM/dd/yyyy")
# Get the mail trace
$params = @{
StartDate = $start
DateEndDate = $endDate
SenderAddress = "email address removed for privacy reasons"
Status = "Failed"
}
Get-MessageTraceV2 @params
Each time I run it, I get an error that the Get-MessageTracev2 is not recognized.
I've confirmed I have ExchangeOnlineManagement module 3.8 installed (Microsoft documentation says the cmdlet was introduced in 3.7).
When I run "Get-Command Get-MessageTraceV2" I get the same message saying the cmdlet is not recognized. When I try "Get-Command *V2" it lists several cmdlets from Microsoft.Graph but nothing from ExchangeOnlineManagement.
I've tried the following all with the same results.
- Uninstalling and reinstalling the ExchangeOnlineManagement module.
- Installing with the -AllowClobber switch.
- Installed PowerShell 7 and installed the 3.9 prerelease.
- On a freshly reset computer, installed ExchangeOnlineManagement module.
- On the fresh computer, I uninstalled and then installed prerelease.
I'm able to use other ExchangeOnlineManagement cmdlets like Get-Mailbox without issues. I am using a GCC tenant if that matters (I hope not).
What am I missing (besides the cmdlet haha)?
2 Replies
- LainRobertsonSilver Contributor
Hi begberts​,
I can't see any references to environment limitations on learn.microsoft.com, so I can't comment on whether being a government cloud matters in this instance, but if we set that one aspect aside, you can run the following command to check if the eligible RBAC roles your account would need to be a member of in order to see and run Get-MessageTraceV2:
Get-ManagementRole -Cmdlet "Get-MessageTraceV2" -CmdletParameters "StartDate", "EndDate", "SenderAddress", "Status" | ForEach-Object { Get-ManagementRoleAssignment -Role $_.Name -Delegating $false; } | Sort-Object -Property RoleAssigneeName, Role | Format-Table -AutoSize -Property Role, RoleAssigneeType, RoleAssigneeName;
The column you're interested in is RoleAssigneeName, where your account would need to be in at least one of the listed roles. As an example of the output, this is what I get for my environment:
As a side note, you've made a syntax error within your $params HashTable, though this doesn't explain the error you're seeing (you'd get a different error if this mattered). DateEndDate should simply be EndDate.
Lastly, Get-Command should only be listing the version imported dynamically by the ExchangeOnlineManagement module as shown below:
Cheers,
Lain
- begbertsCopper Contributor
Thank you for the reply.
I found my answer, and it does indeed look like a GCC issue..."Please note that this timeline applies to our WW environment only and does not affect GCC, GCC-High, DOD, or other sovereign clouds. Timeline for GCC, GCC-High, DoD, and other sovereign clouds will be provided in CY25H2."
Microsoft, if you read this post. PLEASE put a notice at the top of the Get-MessageTraceV2 saying it does not apply to GCC tenants!