When you try to enable a user for Teams DirectRouting and assign a LineURI to a user using a command such as the below
Set-CsUser -Identity user@domain.com -OnPremLineURI “tel:+xxxxxxxxxxxx;ext=xxxx” -EnterpriseVoiceEnabled $true -HostedVoiceMail $true
And you get the following error:
Filter failed to return unique result

This might mean that the LineURI is already assigned to another user
You need to first remove the LineURI from the other users
To remove the Line LineURI (which represents the phone number that is assigned to the user) from a user
Removing the licensing of Office 365 is not enough would disable users on Teams, but the LineURI will remain unusable
To solve the issue, you simply need to run the following on the old user
Set-CSUser olduser@domain.com -OnPremLineURI $null
The would set LineURI and the number will be free to be assigned to another
You can run to assign again the same LineURI to the another user
Set-CsUser -Identity user@domain.com -OnPremLineURI “tel:+xxxxxxxxxxxx;ext=xxxx” -EnterpriseVoiceEnabled $true -HostedVoiceMail $true

