Microsoft Teams – Direct Routing: Error “Filter failed to return unique result” (duplicated phone number – duplicated DDI or duplicated DID)

When enabling a user to Microsoft Teams Direct Routing (let’s say with a phone number – DDI “+44zzzzzzzzzz”) you could have the following error:

Filter failed to return unique result, “[SipAddress : sip:[email protected]] [LineURI :
tel:+44zzzzzzzzzz] [PrivateLine : tel:+44zzzzzzzzzz] “
+ CategoryInfo : InvalidOperation: (Set-CsUser:String) [Set-CsUser], InvalidOperationException
+ FullyQualifiedErrorId : ProcessRecord,Microsoft.Rtc.Management.AD.Cmdlets.SetOcsUserCmdlet
+ PSComputerName :

The error is usually due to the phone number (DDI) being already assigned to another user.
To identify who is the user with the DDI assigned you can use the script below

Get-CsOnlineUser -Filter {LineUri -eq “tel:+44zzzzzzzzzz”}| select firstname,lastname,UserPrincipalName,LineURI,tenantdialplan

You will have a result similar to the one below. Remove the DDI from the wrong user to fix the issue