Search code examples
c#emailazure-active-directoryazure-ad-b2cdelete-row

How to find all users with the same User name\email address in Azure B2C using Azure Active Directory Graph Client?


The B2C Azure AD has users with the same e-mail address like '[email protected]'.

User name                User type       Source                
[email protected]       Member          Azure Active Directory
[email protected]       Member          Microsoft Account
[email protected]       Member          Facebook

Note that what varies is the Source column. The email is the same.

Right now when I do a search like this:

GET https://graph.windows.net/myb2ctenant.onmicrosoft.com/users?api-version=1.6&$filter=signInNames/any(x:x/value%20eq%20%[email protected]%27)

I get just one row: the one with source = Azure Active Directory but not the other 2 from external Identity Providers (IDPs).

How could I retrieve the 3 rows that match this User name\email address in one shot?

Once I get these 3 Users I'd like to delete them.

####### EDIT #######

From Chris Padget answer I could get the users that have Facebook as issuer like this:

Get-User $filter=userIdentities/any(x:x/issuer%20eq%20%27facebook.com%27)

Solution

  • After fiddling with the $filter option, I got it working in a single shot like this:

    Get-User $filter=signInNames/any(x:x/value%20eq%20%[email protected]%27)%20or%20otherMails/any(y:y%20eq%20%[email protected]%27)
    

    For the external Identity Providers we need to check otherMails property.

    #######

    Note: it's necessary to encode the email address. I just tested this $filter using C# code with an email address like [email protected] and it was not retrieving the user. That's because of the + symbol.

    We can use HttpUtility.UrlEncode(email).

    More info here.