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

能否通过azure-cli查询Azure AD已注册设备并按设备名查最近登录用户

使用Azure CLI查询Azure AD已注册设备的相关方法

基础设备查询命令

Azure CLI提供了专门的az ad device命令组用于管理Azure AD中的设备资源,用法和你熟悉的az ad user list完全对齐:

  • 查询所有已注册设备:
    az ad device list
  • 按设备名称精确匹配查询设备:
    az ad device list --filter "displayName eq '你的设备完整名称'"
  • 按设备名称关键词模糊查询设备:
    az ad device list --filter "contains(displayName, '设备名称关键词')"

按设备名称查询最近登录用户

Azure AD设备的基础属性中不会直接存储最近登录用户信息,需要结合租户的登录审计日志查询,操作前请确保你当前登录Azure CLI的账号具备报表读取者或更高的权限:

  1. 先通过设备名称获取设备的唯一ID:
deviceObjectId=$(az ad device list --filter "displayName eq '目标设备名称'" --query "[].deviceId" -o tsv)
  1. 调用图形API查询该设备的最近1条登录记录,提取登录用户信息:
az rest --method get --uri "https://graph.microsoft.com/v1.0/auditLogs/signIns?\$filter=deviceId eq '$deviceObjectId'&\$orderby=createdDateTime desc&\$top=1" --query "value[].{用户名:userPrincipalName,最近登录时间:createdDateTime}" -o table

注意:Azure AD登录日志的保留周期和租户版本有关,免费版默认保留7天,P1/P2付费版最长可保留30天,超出保留周期的历史记录无法查询。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 09:09:04