Last Logged On Time from Exchange Shell stats different from Solarwinds Inactive users tool?

hi guys

So I got some help from EE experts to run a command in Exchange shell to export all mailbox statistics/data.

One of the important things is for me to work out the LastLoggedOnTime so that I can segregate the oldest mailboxes from the actively used ones.

I ran a tool called Inactive Users Tool by Solarwinds and exported it. When I compare the last logged on time of one user from the Exchange shell formula to the data exported from the Solarwinds one, they are different. I have many users who have not logged on for years, but somehow are showing as two days ago in the Shell statistics.

Perhaps the Solarwinds tool is using the Inactive users by looking at a different attribute?

Any ideas on why that would be?

Thanks for helping
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

timgreen7077Exchange EngineerCommented:
see the below link to answer your question

Basically exchange shell is looking at the last time a user or agent accessed the mailbox while solar winds may be looking at the last time the user authenticated to AD.
YashyAuthor Commented:
Ah, that makes sense Tim.

Is there anyway the script you just posted for me, can have the last time the user authenticated to AD at all?
timgreen7077Exchange EngineerCommented:
Here you go. Just copy and paste same as before, and this should work.

$DataPath = "C:\temp\resuts.csv"
$Results = @()
$MailboxUsers = get-mailbox -resultsize unlimited
foreach($user in $mailboxusers)
$UPN = $user.UserPrincipalName
$SAM = $user.SamAccountName
$MbxStats = Get-MailboxStatistics $UPN
$ADUsers = get-aduser -Identity $user.SamAccountName -properties LastLogonDate
      $Properties = @{
      Name = $
      UPN = $UPN
      Alias = $user.alias
      LastLogonDate = $ADUsers.LastLogonDate
      Database = $MbxStats.databasename
      TotaItemSize = $MbxStats.totalitemsize
$Results += New-Object psobject -Property $properties
$Results | Sort-Object -Property TotaItemSize | Select-Object Name,UPN,Alias, LastLogonDate,Database,TotaItemSize | Export-Csv -notypeinformation -Path $DataPath

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maximize Customer Retention with Superior Service

The IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more to help build customer satisfaction and retention.

timgreen7077Exchange EngineerCommented:
Also just a not, since Im not sure what version of powershell you are running, before you copy and paste the cmdlets in exchange shell run the following

import-module activedirectory

Newer versions of powershell will do this automatically since its detecting cmdlets that need the AD modules but older versions didn't so run that first just in case. After that then paste the cmdlets.
YashyAuthor Commented:
Tim, thank you so much for doing this for me. When i run it though, I get errors in Exchange shell as it doesn't recognise the Get-AdUser:

The term 'get-aduser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:6 char:22
+ $ADUsers = get-aduser <<<<  -Identity $user.SamAccountName -properties LastLogonDate
    + CategoryInfo          : ObjectNotFound: (get-aduser:String) [], CommandNotFoundException

Is there a module that needs to be imported?
timgreen7077Exchange EngineerCommented:
import-module activedirectory
YashyAuthor Commented:
Just saw your previous message, hadn't refreshed it.

I tried now, worked a gem:). Thanks a million Tim!!
YashyAuthor Commented:
P.s , where can I get some decent tutorials to learn scripting?
timgreen7077Exchange EngineerCommented:
YouTube is what I use because there are so many free lessons its crazy
Naveen SharmaCommented:
You can also check this earlier discussion for more information about last logon:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.