无法使用通配符搜索模式搜索Microsoft Graph Api V1.0用户



我正在尝试使用以下代码片段基于通配符正则表达式匹配来搜索用户:

var users = await graphServiceClient.Users.Request().Select(e => new {
e.DisplayName,
e.GivenName,
e.PostalCode
}).Filter(RegexMatch(DisplayName("Rob.* Thomas")
).GetAsync();

所以,上面应该匹配用户"Robert Thomas",而RegexMatch目前在过滤器关键字列表中不可用,我只是用它作为例子来实现这项任务。以下内容应与Robin Thomas相匹配:-Filter(RegexMatch(DisplayName("Robin.?Thomas"((以及UserPrincipalName搜索和id搜索等情况下的

我想获得一些类似的结果,但在MS Graph V1.0文档中找不到任何正则表达式搜索。

请帮助我使用MS Graph API V1.0 进行regex匹配

Microsoft GraphV1.0当前不支持像*%like%,尽管目前有$search选项仅在messagesperson集合上受支持。

Work Around:

你可以试试下面的

var users = await graphServiceClient.Users
.Request()
.Filter("startswith(displayName,'Rob') and startswith(UserPrincipalName ,'Thomas')")
.Select( e => new {
e.DisplayName,
e.GivenName,
e.PostalCode
})
.GetAsync();

Note:您可以绑定多个andor子句来执行自定义搜索

希望能有所帮助。

最新更新