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

使用Microsoft GraphAPI将SharePoint人员字段LookupID转换为邮箱

解决方案:将SharePoint列表人员字段LookupID转换为邮箱(仅用Microsoft Graph API)

核心说明

SharePoint列表中人员字段返回的LookupID是站点本地用户ID,并非Azure AD全局用户ID,因此不能直接用Get-MgUser查询。需要先通过站点用户ID关联到对应的用户信息,或在列表查询阶段直接获取邮箱信息。


方法1:通过站点用户ID直接查询邮箱

使用Graph API的/sites/{site-id}/users/{lookup-id}端点,传入你的站点ID和人员字段的LookupID,即可获取包含邮箱的用户详情。

PowerShell代码示例

# 定义站点ID和LookupID
$siteId = "your-site-id" # 可通过Get-MgSite获取目标站点ID
$buyerLookupId = "45"

# 查询站点用户信息
$siteUser = Get-MgSiteUser -SiteId $siteId -UserId $buyerLookupId

# 提取邮箱(userPrincipalName对应用户邮箱)
$buyerEmail = $siteUser.UserPrincipalName
Write-Host "Buyer邮箱:$buyerEmail"

方法2:查询列表时直接展开人员字段获取邮箱

在查询SharePoint列表时,通过$expand参数直接展开人员字段,无需后续转换LookupID,一步到位获取邮箱。

PowerShell代码示例

$siteId = "your-site-id"
$listId = "your-list-id" # 可通过Get-MgSiteList获取目标列表ID

# 查询列表并展开Buyer字段,指定返回邮箱和名称
$listItems = Get-MgSiteListItem -SiteId $siteId -ListId $listId -ExpandProperty "fields(`$select=Buyer/Email,Buyer/Title)"

# 遍历列表项提取邮箱
foreach ($item in $listItems) {
    $buyerEmail = $item.Fields.AdditionalProperties["Buyer/Email"]
    Write-Host "列表项ID $($item.Id) 的Buyer邮箱:$buyerEmail"
}

权限要求

确保你的Azure应用已配置以下Graph API应用权限:

  • Sites.Read.All 或 Sites.ReadWrite.All
  • 若需通过站点用户ID进一步获取Azure AD用户完整信息,需额外配置User.Read.All

内容的提问来源于stack exchange,提问作者Mark D. MacLachlan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 04:40:59