fr0stbyt3
fr0stbyt3

Reputation: 21

Sort LastLogonTime -Descending Gives Identity Error

I am trying to sort LastLogonTime by descending order for users in my Exchange Online platform.

Pulling up the users comes through just fine showing their display name and last logon time with the below code.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime

When I add the sort command:

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime | Sort LastLogonTime -Descending

I am given this error on all accounts:

Get-MailboxStatistics: Ex838C9A|Microsoft.Exchange.Configuration.Tasks.ManagementObjectAmbiguousException|The specified mailbox Identity:"sales"  isn't
unique.

Not sure what is going on since the users are pulled just fine without the sort command. Any suggestions?

I tried to sort lastlogontime by using the line, expecting the results to print in descending order of time:

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime | Sort LastLogonTime -Descending

Upvotes: 2

Views: 49

Answers (1)

CraftyB
CraftyB

Reputation: 746

From trial and error I have been able to identify the following;

The likely cause is that multiple mailboxes have the same alias, this can be found by trialing the following command; (You would identify the offending mailbox from the error specified.)

Get-Mailbox sales

If this yields multiple results, you can then trial the following to confirm that this is what is causing the error by using the following command;

Get-MailboxStatistics sales

This should throw the same error as you had before, the reason why you may have not of seen this when removing the sort command is that it will provide the results for valid mailbox identities and throw the errors between these responses.

There is a couple of work around's to this issue;

1, Updating the alias on mailboxes that have duplicates, if synchronized from local AD to office 365 you will need to update the mailNickname in active directory to facilitate this.

2, Adapt the script to allow the pipeline to use a different value;

Get-Mailbox -ResultSize Unlimited | Select -expand UserPrincipalName | Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime | Sort LastLogonTime -Descending

Upvotes: 1

Related Questions