Got error "The specified mailbox "xxxxxxx" isn't unique" when trying to Get-InboxRule

New Contributor

Hi all,


Hope all is well with you.


I'm trying to get a list of InboxRule which is configured to forward/redirect email to external email address for all email accounts. Below is the script that I run and I'm getting result in Excel, but sometimes I got "The specified mailbox "xxxxxxx" isn't unique" when querying a user with multiple AD accounts in same Display Name but different email address. I assume the Get-InboxRule will get the PrimarySmtpAddress which is the actual email address of the account instead of using the DisplayName. Thank you.


Get-Mailbox -ResultSize unlimited |
%{Get-InboxRule -Mailbox $_.PrimarySmtpAddress} |
%{Get-InboxRule -Mailbox $_.PrimarySmtpAddress -Identity $_.identity | where {$_.RedirectTo -like "*@*" -or $_.ForwardTo -like "*@*"}} |
Select-Object Name, Enabled, Priority, RuleIdentity, @{Name="MailboxOwnerId"; Expression = {$_.MailboxOwnerId}}, @{Name="ForwardTo"; Expression = {$_.ForwardTo}}, @{Name="RedirectTo"; Expression = {$_.RedirectTo}} |
Export-Csv InboxRule.csv



The specified mailbox "user A" isn't unique.
+ CategoryInfo : NotSpecified: (:) [Get-InboxRule], ManagementObjectAmbiguousException
+ FullyQualifiedErrorId : [Server=SG2PR01MB2203,RequestId=f1a42c7b-fe25-4846-941c-e2febc59186c,TimeStamp=6/3/2020 9:53:29 AM] [FailureCategory=Cmdlet-ManagementObjectAmbiguousException] 292755
+ PSComputerName :


4 Replies

Using an unique identifier is the correct way to do this, however you might still have some objects in "broken" state, with duplicate attribute values. I'd suggest checking manually the mailboxes returned in those errors.


Also, why the double foreach loop? You can get all the details from the first call of Get-InboxRule.

@Vasil Michev


Thanks for the reply. Im using PrimarySmtpAddress which is a unique identifier but just somehow the second for loop cannot get the right value from the Get-Mailbox. And the reason i used double for loop is because the second one need to get the identity value from the first for loop but it also need to get the PrimarySmtpAddress from the Get-Mailbox. So im not sure how it can be archived. 

best response confirmed by ThomasLam (New Contributor)

You already have all the information you need, no need to request it again. Here's a sample script I wrote a while back for the same scenario:

Hi @Vasil,
Thank you for sharing :-), however, the link has broken.