powershell 获取Azure AD用户上次登录日期

az31mfrm  于 2022-11-10  发布在  Shell
关注(0)|答案(2)|浏览(317)

我想使用PowerShell获取Azure AD用户的此日期。

我不能使用Get-AzureADAuditSignInLogs,因为很多用户已经超过30天没有登录了。我有兴趣寻找用户的最后一次登录是60-90天前。

8zzbczxx

8zzbczxx1#

你可以通过下面的脚本获取Azure AD用户的上次登录日期,方法是在提升的PowerShell中执行该脚本。你只需要提供你的Azure AD租户的全局管理员凭据,下面的脚本将获取你的Microsoft 365租户中所有用户的上次登录日期的详细信息。

$LiveCred = Get-Credential
   $Session = New-PSSession -ConfigurationName Microsoft.Exchange - 
     ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
   Set-ExecutionPolicy RemoteSigned
      Import-PSSession $Session
    (Get-Mailbox) | Foreach {Get-MailboxStatistics $_.Identity | Select DisplayName, LastLogonTime} | Export-CSV $Home\Desktop\LastLogonDate.csv
   Remove-PSSession $Session

请查看其输出如下:

通过这种方式,您可以检索租户中任何Azure AD用户的上次登录详细信息。您只需确保用户拥有Office 365许可证并使用邮件进行通信即可。有关脚本的更多详细信息,请访问以下链接:-
https://community.spiceworks.com/scripts/show/2290-last-log-in-time-and-date-powershell-script-for-office-365-to-desktop-csv-file

toe95027

toe950272#

这可能是真的,但现在不是。我在对账,并运行了这个程序,但它没有任何意义,因为我知道这些帐户是不活动的。它返回的最近登录值与登录日志不匹配。LastUserInteraction,更接近事实,但也不完美。例如,当我检查Azure用户配置文件时,它显示上次登录日期,但这与LastLogin或LastUserIneraction都不匹配

相关问题