You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Graph API获取Azure AD属性编辑器中的employeeNumber

获取Azure AD中employeeNumber字段的解决方案

1. 切换到Beta版Graph SDK

employeeNumber属性仅在Microsoft Graph的Beta版本中对外开放,因此需要在项目中安装Microsoft.Graph.Beta NuGet包(替换原有的Microsoft.Graph包)。

2. 修改代码添加employeeNumber字段

更新你的用户查询代码,在Select语句中直接包含EmployeeNumber属性(对应Azure AD属性编辑器中的employeeNumber字段):

public static Task<IGraphServiceUsersCollectionPage> GetUsersAsync()
{
    EnsureGraphForAppOnlyAuth();
    _ = _appClient ??
        throw new System.NullReferenceException("Graph has not been initialized for app-only auth");

    return _appClient.Users
        .Request()
        .Select(u => new
        {
            u.DisplayName,
            u.GivenName,
            u.Surname,
            u.Id,
            u.EmployeeId,
            u.MobilePhone,
            u.BusinessPhones,
            u.Mail,
            u.CompanyName,
            u.City,
            u.UserPrincipalName,
            u.OnPremisesExtensionAttributes,
            // 新增:获取employeeNumber字段
            u.EmployeeNumber
        })
        .Expand(u => u.Manager)
        .Top(999)
        .OrderBy("DisplayName")
        .GetAsync();
}

3. 确认应用权限

确保Azure AD中你的应用注册已配置User.Read.All应用权限(需管理员同意),否则会因权限不足无法读取该字段。

额外验证:本地AD同步场景

如果employeeNumber是从本地Active Directory同步到Azure AD的,也可以尝试读取OnPremisesEmployeeId属性(部分同步场景下会映射到这个字段),只需在Select中添加:

u.OnPremisesEmployeeId

内容的提问来源于stack exchange,提问作者Dradoris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 07:52:54