// See https://aka.ms/new-console-template for more information// https://graph.microsoft.com/v1.0/users?$filter=endsWith(userPrincipalName, 'contoso.com%23EXT%23%40microsoft.onmicrosoft.com')&$select=userPrincipalName&$count=trueusingAzure.Identity;usingMicrosoft.Graph;usingMicrosoft.Graph.Models;vardomainList=newDictionary<string,List<string>>(){{"Contoso",newList<string>(){"contoso.com#EXT#@microsoft.onmicrosoft.com",}},{"Fabrikam",newList<string>(){"fabrikam.com#EXT#@microsoft.onmicrosoft.com",}}};vardefaultAzureCredential=newDefaultAzureCredential();vargraphServiceClient=newGraphServiceClient(defaultAzureCredential);varcount=0;usingvarstreamWriter=newStreamWriter("output.csv");foreach(varkvpindomainList){foreach(vardomaininkvp.Value){varuserCollectionResponse=awaitgraphServiceClient.Users.GetAsync((requestConfiguration)=>{requestConfiguration.Headers.Add("ConsistencyLevel","eventual");requestConfiguration.QueryParameters.Filter=$"endsWith(userPrincipalName, '{domain}')";requestConfiguration.QueryParameters.Select=new[]{"id, displayName, userPrincipalName"};requestConfiguration.QueryParameters.Count=true;});if(userCollectionResponse!=null){varpageIterator=PageIterator<User,UserCollectionResponse>.CreatePageIterator(graphServiceClient,userCollectionResponse,async(user)=>{awaitstreamWriter.WriteLineAsync($"{count++}, {kvp.Key}, {user.Id}, {user.DisplayName}, {user.UserPrincipalName}");returntrue;});awaitpageIterator.IterateAsync();}}}graphServiceClient.Dispose();