SOLVED
Home

List all users' last login date

%3CLINGO-SUB%20id%3D%22lingo-sub-109212%22%20slang%3D%22en-US%22%3EList%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-109212%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20it%20possible%2C%20using%20PowerShell%2C%20to%20list%20all%20AAD%20users'%20last%20login%20date%20(no%20matter%20how%20they%20logged%20in)%3F%20I%20have%20found%20a%20couple%20of%20scripts%20that%20check%20the%20last%20mailbox%20login%2C%20but%20that%20is%20not%20what%20we%20need%2C%20because%20we%26nbsp%3Balso%20want%20to%20list%20unlicensed%20users.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-109212%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Elogin%20date%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-204989%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-204989%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%20not%20only%20unreliable%2C%20it's%20impossible.%20Get-MailboxStatistics%20only%20returns%20statistics%20for%20mailboxes%2C%20but%20I%20specifically%20need%20logon%20statistics%20for%20people%20who%20do%20not%20have%20mailboxes.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-204043%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-204043%22%20slang%3D%22en-US%22%3E%3CP%3EJust%20a%20warning%20that%20using%20the%20Get-MailboxStatistics%20cmdlet%20to%20get%20this%20information%20is%20highly%20unreliable%20(see%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F64%22%20target%3D%22_blank%22%3E%40Tony%20Redmond%3C%2FA%3E's%20great%20blog%20on%20that%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.petri.com%2Fget-mailboxstatistics-cmdlet-wrong%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.petri.com%2Fget-mailboxstatistics-cmdlet-wrong%3C%2FA%3E).%20The%20Office%20365%20usage%20reports%20is%20really%20the%20better%20answer%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-204017%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-204017%22%20slang%3D%22en-US%22%3E%3CP%3EWhat%20about%20users%20who%20don't%20have%20mailboxes%3F%20I%20have%20a%20number%20of%20users%20for%20whom%20we%20have%20disabled%20the%20Exchange%20Online%20license.%20How%20can%20I%20get%20their%20logon%20statistics%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192371%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192371%22%20slang%3D%22en-US%22%3E%3CP%3EOnce%20you've%20logged%20in%20and%20authenticated%20against%20your%20Office%20365%20tenant%2C%20you%20can%20then%20use%20the%20below%20commands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Connects%20you%20to%20Windows%20Azure%20Active%20Directory%3C%2FP%3E%3CP%3EConnect-MsolService%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Gets%20Unlicenced%20users%20and%20lists%20the%20%22DisplayName%2C%20LastLogonTime%20and%20LastLogoffTime%22%3C%2FP%3E%3CP%3EGet-MsolUser%20-UnlicensedUsersOnly%20%7C%20Foreach%20%7BGet-MailboxStatistics%20%24_.UserPrincipalName%20%7C%20Select%20DisplayName%2C%20LastLogonTime%2C%20LastLogoffTime%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192357%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192357%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Robert%2C%3C%2FP%3E%3CP%3EI%20tested%20the%20script%20it%20also%20provides%20the%20logon%20times%20for%20%22Unlicensed%20Users%22%20as%20well%20and%20exports%20them%20to%20a%20.CSV.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192334%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192334%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20provided%20script%20gives%20you%20the%20last%20login%20information%20of%20users%20who%20have%20Exchange%20Online%20license%20whereas%20the%20requirement%20is%20to%20display%20%22last%20logon%20time%22%20of%20unlicensed%20users%20as%20well.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192290%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192290%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20might%20give%20you%20what%20you're%20after...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.spiceworks.com%2Fscripts%2Fshow%2F2290-last-log-in-time-and-date-powershell-script-for-office-365-to-desktop-csv-file%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcommunity.spiceworks.com%2Fscripts%2Fshow%2F2290-last-log-in-time-and-date-powershell-script-for-office-365-to-desktop-csv-file%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-130901%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-130901%22%20slang%3D%22en-US%22%3E%3CP%3EI%20think%20this%20is%20what%20you%20need.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20890px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F24653iDD88CE951BF2E97A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Login%20Activities.JPG%22%20title%3D%22Login%20Activities.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20above%20functionality%20is%20available%26nbsp%3Bin%20%3CA%20href%3D%22https%3A%2F%2Fadmindroid.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAdminDroid%20Office%20365%20Reporter%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-109987%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-109987%22%20slang%3D%22en-US%22%3EThanks%2C%20Vasil.%20That%20will%20have%20to%20do%2C%20but%20what%20I%20really%20needed%20was%20to%20be%20able%20to%20sort%20on%20user%20type%20(internal%20user%2C%20guest%20user%2C%20administrator%20etc.)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-109654%22%20slang%3D%22en-US%22%3ERe%3A%20List%20all%20users'%20last%20login%20date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-109654%22%20slang%3D%22en-US%22%3E%3CP%3ENo.%20Use%20the%20report%20in%20the%20O365%20admin%20center%20-%26gt%3B%20Reports%20-%26gt%3B%20Usage%20-%26gt%3B%20Active%20users.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Is it possible, using PowerShell, to list all AAD users' last login date (no matter how they logged in)? I have found a couple of scripts that check the last mailbox login, but that is not what we need, because we also want to list unlicensed users.

10 Replies
Solution

No. Use the report in the O365 admin center -> Reports -> Usage -> Active users.

Thanks, Vasil. That will have to do, but what I really needed was to be able to sort on user type (internal user, guest user, administrator etc.)

I think this is what you need.

Login Activities.JPG

 

The above functionality is available in AdminDroid Office 365 Reporter.

The provided script gives you the last login information of users who have Exchange Online license whereas the requirement is to display "last logon time" of unlicensed users as well.

Hi Robert,

I tested the script it also provides the logon times for "Unlicensed Users" as well and exports them to a .CSV.

Once you've logged in and authenticated against your Office 365 tenant, you can then use the below commands.

 

# Connects you to Windows Azure Active Directory

Connect-MsolService

 

# Gets Unlicenced users and lists the "DisplayName, LastLogonTime and LastLogoffTime"

Get-MsolUser -UnlicensedUsersOnly | Foreach {Get-MailboxStatistics $_.UserPrincipalName | Select DisplayName, LastLogonTime, LastLogoffTime}

What about users who don't have mailboxes? I have a number of users for whom we have disabled the Exchange Online license. How can I get their logon statistics?

Just a warning that using the Get-MailboxStatistics cmdlet to get this information is highly unreliable (see @Tony Redmond's great blog on that here: https://www.petri.com/get-mailboxstatistics-cmdlet-wrong). The Office 365 usage reports is really the better answer here.

It's not only unreliable, it's impossible. Get-MailboxStatistics only returns statistics for mailboxes, but I specifically need logon statistics for people who do not have mailboxes.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies