Mar 24 2020
12:43 PM
- last edited on
Feb 06 2023
04:08 AM
by
TechCommunityAP
Mar 24 2020
12:43 PM
- last edited on
Feb 06 2023
04:08 AM
by
TechCommunityAP
Is there anyway to download via powershell the last login time for all users? Currently I'm using "Get-EXOMailboxStatistics" but this requires you to provide a username and only obtains the stats for this user, the problem being we have over 300,000 users so this takes nearly a week to run!!!!!
Mar 25 2020 12:22 AM
The data you get from Get-MailboxStatistics is incorrect anyway, you shouldn't use that. Use the built-in reports from the O365 admin center, or the corresponding Graph endpoints. Or the recently introduced /signInActivity endpoint, but that's per user also: https://docs.microsoft.com/en-us/graph/api/resources/signinactivity?view=graph-rest-beta
Mar 25 2020 03:58 AM
Yes. What Vasil said was correct - LastLogonTime from Get-MailBoxStatistics shows wrong value.
To get all users last activity time/real last logon time, you can use this script: Export Office 365 users Real Last Logon Time Report to CSV
Mar 25 2020 07:43 AM
Thanks for the feedback, obtain the data via the Graph API is fine, the problem is that we need to make a call for each user rather than requesting the info for all users. Is there anyway to do this in bulk and obtain the stats for all users in our Org? The root issue for us is that we need to make a call for each user.
Mar 25 2020 07:48 AM
Hi Kathy,
Thanks for your suggestion, but looking at this script I think I will hit the same issue as it looks like it makes a call to O365/Azure for each user:-
Function Get_LastLogonTime { $MailboxStatistics=Get-MailboxStatistics -Identity $upn
I'm trying to find a way to request the stats for all users with a single call (or at least not 300,000+ calls)
Mar 25 2020 09:48 AM
Use the Graph call for the report then, it will give you the data for all users.
Mar 25 2020 10:30 AM
I presume this would be a call to the auditLogs/signIns endpoint - but this looks like it's only in beta. Is there the same in pro?
Mar 26 2020 12:35 AM
Jul 06 2022 12:38 AM - edited Aug 01 2022 08:14 PM
I wrote a detailed document on this. The solution returns, DisplayName, UserPrincipleName, LastLogin.
$mailboxes = Get-EXOMailbox -ResultSize Unlimited $mailboxes | ForEach-Object { $mbx = $_ $mbs = Get-EXOMailboxStatistics -Identity $mbx.UserPrincipalName | Where-Object LastLogonTime -LE (Get-Date).AddDays(-90) | Select DisplayName, LastLogonTime if ($mbs.LastLogonTime -ne $null){ $lt = $mbs.LastLogonTime }else{ $lt = "Normal User" } New-Object -TypeName PSObject -Property @{ DisplayName = $mbx.DisplayName UserPrincipalName = $mbx.UserPrincipalName LastLogonTime = $lt} }
You can read the complete from my blog: Get Last Logon Time of Office 365 Users PowerShell