We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

High Priority
330 Views
Last Modified: 2018-07-17
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

timgreen7077Exchange Engineer
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
timgreen7077Exchange Engineer
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.