You need to enable JavaScript to run this app. Azure AD中查询用户配置文件是否上传头像的PowerShell命令问询
优惠活动
大模型
产品
解决方案
定价
更多

Azure AD中查询用户配置文件是否上传头像的PowerShell命令问询

解决方案

可以通过Microsoft Graph PowerShell模块实现该需求,以下是具体操作方法:

前置操作

  • 首先安装Microsoft Graph PowerShell模块:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • 连接Microsoft Graph并授予读取用户信息的权限:
    Connect-MgGraph -Scopes "User.Read.All"
    首次连接会弹出授权窗口,使用全局管理员或用户管理员账号同意权限申请即可。

单用户头像状态检测

执行以下命令可直接返回指定用户的头像上传状态:

# 将等号后内容替换为目标用户的用户主体名
$targetUser = "lisi@contoso.com"
$photoStatus = Get-MgUserPhotoStatus -UserId $targetUser -ErrorAction SilentlyContinue
$output = if ($photoStatus) {"是"} else {"否"}
Write-Host "用户头像上传状态:$output"

批量用户头像审计(适配HR部门审计场景)

如果需要导出全租户所有用户的头像状态,可使用以下脚本直接生成审计CSV文件:

$auditList = @()
# 获取租户内所有用户信息
$allUsers = Get-MgUser -All -Property DisplayName,UserPrincipalName,Id
foreach ($user in $allUsers) {
    $hasPhoto = if (Get-MgUserPhotoStatus -UserId $user.Id -ErrorAction SilentlyContinue) {"是"} else {"否"}
    $auditList += [PSCustomObject]@{
        员工姓名 = $user.DisplayName
        账号邮箱 = $user.UserPrincipalName
        账号ID = $user.Id
        是否已上传头像 = $hasPhoto
    }
}
# 导出结果到本地CSV,可自定义保存路径
$auditList | Export-Csv -Path "D:\AzureAD用户头像审计结果.csv" -Encoding UTF8 -NoTypeInformation

脚本执行完成后,打开导出的CSV即可直接查看所有用户的头像上传状态。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.11 03:03:03