Office 365 LastLogonTime report. Find inactive users on Office 365.

Took me a while to find this code on another site.. I’ve modified it slightly.

This reports the last log on date of every user in your organisation.

$objUsers = get-mailbox -ResultSize Unlimited | select UserPrincipalName 

Foreach ($objUser in $objUsers) 
    {     
        #Connect to the users mailbox 
        $objUserMailbox = get-mailboxstatistics -Identity $($objUser.UserPrincipalName) | Select LastLogonTime 
         
        #Prepare UserPrincipalName variable 
        $strUserPrincipalName = $objUser.UserPrincipalName 
         
        #Check if they have a last logon time. Users who have never logged in do not have this property 
        if ($objUserMailbox.LastLogonTime -eq $null) 
        { 
            #Never logged in, update Last Logon Variable 
            $strLastLogonTime = "Never Logged In" 
        } 
        else 
        { 
            #Update last logon variable with data from Office 365 
            $strLastLogonTime = $objUserMailbox.LastLogonTime 
        } 
         
        #Output result to screen for debuging (Uncomment to use) 
        write-host "$strUserPrincipalName : $strLastLogonTime"
    }

Copy and paste it into the PowerShell after connecting and then press enter twice.. Should show you a list of users and their last sign in time.

Hope this helps someone.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Office 365 LastLogonTime report. Find inactive users on Office 365.

  1. Jimmy says:

    What if the user does not have a mailbox? Perhaps I’ve provisioned a user and only want them to use SharePoint online so I don’t give them Exchange, is there an option for finding out last logon?

  2. Robert says:

    The below GUI tool gives you inactive users on all Office 365 services and also you can find the inactive users by their last activity type such as last mail read time, last mail sent time, last team message sent, last yammer post time etc.

    https://gallery.technet.microsoft.com/office/Office-365-Reporting-Tool-7987b4c2

    Following are the some of the inactive Office 365 user reports which are available in the above tool.

    Inactive Exchange Users by Last Mail Read Date
    Inactive Exchange Users by Last Mail Sent Date
    Inactive Exchange Users by Last Mail Received Date
    Inactive SharePoint Users by Last File Accessed Date
    Inactive SharePoint Users by Last File Synced Date
    Inactive SharePoint Users by Last External File Sharing Date
    Inactive SharePoint Users by Last Internal File Sharing Date
    Inactive SharePoint Users by Last Page Accessed Date
    Inactive OneDrive Users by ‘Last File Access Date’
    Inactive OneDrive Users by ‘Last Internal Sharing Activity’
    Inactive OneDrive Users by ‘Last External Sharing Activity’
    Inactive OneDrive Users by ‘Last File Synced Time’
    Inactive Yammer Users by Last Like Received Date
    Inactive Yammer Users by Last Post Posted Date
    Inactive Yammer Users by Last Post Read Date
    Inactive Yammer Users by Last Activity Date
    Inactive Teams Users by Last Team Chat Message Sent
    Inactive Teams Users by Last Private Chat Message Sent
    Inactive Teams Users by Last Call Activity
    Inactive Teams Users by Last Meeting Activity
    Last Active Time of Users by Office 365 Services
    Daily Active User Count by Office 365 Services

  3. Really good, thanks!

Comment on this topic

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s