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

Yashy
Yashy used Ask the Experts™
on
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
Yashy
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
timgreen7077Exchange Engineer
Distinguished Expert 2018

Commented:
see the below link to answer your question

https://social.technet.microsoft.com/Forums/windowsserver/en-US/ed694f51-12e0-446f-8312-74c630fd33b0/lastlogintime-of-mailbox-and-lastlogon-of-user?forum=winserverDS


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.

Author

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?
Exchange Engineer
Distinguished Expert 2018
Commented:
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 = $user.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
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

timgreen7077Exchange Engineer
Distinguished Expert 2018

Commented:
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.

Author

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 Engineer
Distinguished Expert 2018

Commented:
import-module activedirectory

Author

Commented:
Just saw your previous message, hadn't refreshed it.

I tried now, worked a gem:). Thanks a million Tim!!

Author

Commented:
P.s , where can I get some decent tutorials to learn scripting?
timgreen7077Exchange Engineer
Distinguished Expert 2018

Commented:
YouTube is what I use because there are so many free lessons its crazy
You can also check this earlier discussion for more information about last logon: https://www.experts-exchange.com/questions/29083863/AD-last-logon-vs-Mailbox-last-logon.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial