SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1435742%22%20slang%3D%22en-US%22%3EGot%20error%20%22The%20specified%20mailbox%20%22xxxxxxx%22%20isn't%20unique%22%20when%20trying%20to%20Get-InboxRule%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1435742%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20all%20is%20well%20with%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20get%20a%20list%20of%20InboxRule%20which%20is%20configured%20to%20forward%2Fredirect%20email%20to%20external%20email%20address%20for%20all%20email%20accounts.%20Below%20is%20the%20script%20that%20I%20run%20and%20I'm%20getting%20result%20in%20Excel%2C%20but%20sometimes%20I%20got%20%22The%20specified%20mailbox%20%22xxxxxxx%22%20isn't%20unique%22%20when%20querying%20a%20user%20with%20multiple%20AD%20accounts%20in%20same%20Display%20Name%20but%20different%20email%20address.%26nbsp%3BI%20assume%20the%20Get-InboxRule%20will%20get%20the%20PrimarySmtpAddress%20which%20is%20the%20actual%20email%20address%20of%20the%20account%20instead%20of%20using%20the%20DisplayName.%20Thank%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-Mailbox%20-ResultSize%20unlimited%20%7C%3CBR%20%2F%3E%25%7BGet-InboxRule%20-Mailbox%20%24_.PrimarySmtpAddress%7D%20%7C%3CBR%20%2F%3E%25%7BGet-InboxRule%20-Mailbox%20%24_.PrimarySmtpAddress%20-Identity%20%24_.identity%20%7C%20where%20%7B%24_.RedirectTo%20-like%20%22*%40*%22%20-or%20%24_.ForwardTo%20-like%20%22*%40*%22%7D%7D%20%7C%3CBR%20%2F%3ESelect-Object%20Name%2C%20Enabled%2C%20Priority%2C%20RuleIdentity%2C%20%40%7BName%3D%22MailboxOwnerId%22%3B%20Expression%20%3D%20%7B%24_.MailboxOwnerId%7D%7D%2C%20%40%7BName%3D%22ForwardTo%22%3B%20Expression%20%3D%20%7B%24_.ForwardTo%7D%7D%2C%20%40%7BName%3D%22RedirectTo%22%3B%20Expression%20%3D%20%7B%24_.RedirectTo%7D%7D%20%7C%3CBR%20%2F%3EExport-Csv%20InboxRule.csv%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EError%3A%3C%2FP%3E%3CP%3EThe%20specified%20mailbox%20%22user%20A%22%20isn't%20unique.%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20NotSpecified%3A%20(%3A)%20%5BGet-InboxRule%5D%2C%20ManagementObjectAmbiguousException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20%5BServer%3DSG2PR01MB2203%2CRequestId%3Df1a42c7b-fe25-4846-941c-e2febc59186c%2CTimeStamp%3D6%2F3%2F2020%209%3A53%3A29%20AM%5D%20%5BFailureCategory%3DCmdlet-ManagementObjectAmbiguousException%5D%20292755%3CBR%20%2F%3EA9%2CMicrosoft.Exchange.Management.RecipientTasks.GetInboxRule%3CBR%20%2F%3E%2B%20PSComputerName%20%3A%20outlook.office365.com%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1435742%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1436867%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20error%20%22The%20specified%20mailbox%20%22xxxxxxx%22%20isn't%20unique%22%20when%20trying%20to%20Get%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1436867%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20an%20unique%20identifier%20is%20the%20correct%20way%20to%20do%20this%2C%20however%20you%20might%20still%20have%20some%20objects%20in%20%22broken%22%20state%2C%20with%20duplicate%20attribute%20values.%20I'd%20suggest%20checking%20manually%20the%20mailboxes%20returned%20in%20those%20errors.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlso%2C%20why%20the%20double%20foreach%20loop%3F%20You%20can%20get%20all%20the%20details%20from%20the%20first%20call%20of%20Get-InboxRule.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1437520%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20error%20%22The%20specified%20mailbox%20%22xxxxxxx%22%20isn't%20unique%22%20when%20trying%20to%20Get%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1437520%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20reply.%20Im%20using%20PrimarySmtpAddress%20which%20is%20a%20unique%20identifier%20but%20just%20somehow%20the%20second%20for%20loop%20cannot%20get%20the%20right%20value%20from%20the%20Get-Mailbox.%20And%20the%20reason%20i%20used%20double%20for%20loop%20is%20because%20the%20second%20one%20need%20to%20get%20the%20identity%20value%20from%20the%20first%20for%20loop%20but%20it%20also%20need%20to%20get%20the%20PrimarySmtpAddress%20from%20the%20Get-Mailbox.%20So%20im%20not%20sure%20how%20it%20can%20be%20archived.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1439491%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20error%20%22The%20specified%20mailbox%20%22xxxxxxx%22%20isn't%20unique%22%20when%20trying%20to%20Get%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1439491%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20already%20have%20all%20the%20information%20you%20need%2C%20no%20need%20to%20request%20it%20again.%20Here's%20a%20sample%20script%20I%20wrote%20a%20while%20back%20for%20the%20same%20scenario%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.quadrotech-it.com%2Fblog%2Foffice-365-permissions-inventory-mailbox-forwarding%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.quadrotech-it.com%2Fblog%2Foffice-365-permissions-inventory-mailbox-forwarding%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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

 

Error:

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
A9,Microsoft.Exchange.Management.RecipientTasks.GetInboxRule
+ PSComputerName : outlook.office365.com

 

3 Replies
Highlighted

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.

Highlighted

@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. 

Highlighted
Best Response confirmed by ThomasLam (New Contributor)
Solution

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: https://www.quadrotech-it.com/blog/office-365-permissions-inventory-mailbox-forwarding/