Forum Discussion
Last Logon time
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!!!!!
- kathyBrass Contributor
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
- nimbyCopper Contributor
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)
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
- nimbyCopper Contributor
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.
Use the Graph call for the report then, it will give you the data for all users.