in src/Graph.Rbac/Version1_6/ActiveDirectory/ActiveDirectoryClient.cs [198:259]
public IEnumerable<PSADUser> FilterUsers(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
{
if (!string.IsNullOrEmpty(options.Id))
{
User user = null;
try
{
user = GraphClient.Users.Get(Normalize(options.Id));
}
catch { /* The user does not exist, ignore the exception. */ }
if (user != null)
{
return new List<PSADUser> { user.ToPSADUser() };
}
}
else if (!string.IsNullOrEmpty(options.UPN) || !string.IsNullOrEmpty(options.Mail))
{
IPage<User> result = null;
try
{
string upnOrMail = Normalize(options.UPN) ?? Normalize(options.Mail);
var odataQuery = new Rest.Azure.OData.ODataQuery<User>();
if (!string.IsNullOrEmpty(options.UPN))
{
odataQuery.SetFilter(u => u.UserPrincipalName == upnOrMail);
}
else
{
odataQuery.SetFilter(u => u.Mail == upnOrMail);
}
result = GraphClient.Users.List(odataQuery);
}
catch { /* The user does not exist, ignore the exception. */ }
if (result != null)
{
return result.Select(u => u.ToPSADUser());
}
}
else
{
Rest.Azure.OData.ODataQuery<User> odataQuery = null;
if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
{
options.SearchString = options.SearchString.TrimEnd('*');
odataQuery = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName.StartsWith(options.SearchString));
}
else
{
odataQuery = new Rest.Azure.OData.ODataQuery<User>(u => u.DisplayName == options.SearchString);
}
return new GenericPageEnumerable<User>(
delegate ()
{
return GraphClient.Users.List(odataQuery.ToString());
}, GraphClient.Users.ListNext, first, skip).Select(u => u.ToPSADUser());
}
return new List<PSADUser>();
}